Browse Source

Merge pull request #9067 from nextcloud/bugfix/8404/fix-json-output

Fix json output
pull/9409/head
Joas Schilling 3 years ago
committed by GitHub
parent
commit
8455abbb33
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      docs/occ.md
  2. 3
      lib/Command/Command/Add.php
  3. 2
      lib/Command/Command/AddSamples.php
  4. 2
      lib/Command/Command/ListCommand.php
  5. 6
      lib/Command/Command/TRenderCommand.php
  6. 3
      lib/Command/Command/Update.php
  7. 1
      tests/integration/features/bootstrap/CommandLineTrait.php
  8. 24
      tests/integration/features/command/command-list.feature

12
docs/occ.md

@ -6,7 +6,7 @@ Add a new command
### Usage
* `talk:command:add <cmd> <name> <script> <response> <enabled>`
* `talk:command:add [--output [OUTPUT]] [--] <cmd> <name> <script> <response> <enabled>`
| Arguments | Description | Is required | Is array | Default |
|---|---|---|---|---|
@ -16,6 +16,10 @@ Add a new command
| `response` | Who should see the response: 0 - No one, 1 - User, 2 - All | yes | no | `NULL` |
| `enabled` | Who can use this command: 0 - Disabled, 1 - Moderators, 2 - Users, 3 - Guests | yes | no | `NULL` |
| Options | Accept value | Is value required | Is multiple | Default |
|---|---|---|---|---|
| `--output` | Output format (plain, json or json_pretty, default is plain) | yes | no | no | 'plain'` |
## talk:command:add-samples
Adds some sample commands: /wiki, …
@ -58,7 +62,7 @@ Add a new command
### Usage
* `talk:command:update <command-id> <cmd> <name> <script> <response> <enabled>`
* `talk:command:update [--output [OUTPUT]] [--] <command-id> <cmd> <name> <script> <response> <enabled>`
| Arguments | Description | Is required | Is array | Default |
|---|---|---|---|---|
@ -69,6 +73,10 @@ Add a new command
| `response` | Who should see the response: 0 - No one, 1 - User, 2 - All | yes | no | `NULL` |
| `enabled` | Who can use this command: 0 - Disabled, 1 - Moderators, 2 - Users, 3 - Guests | yes | no | `NULL` |
| Options | Accept value | Is value required | Is multiple | Default |
|---|---|---|---|---|
| `--output` | Output format (plain, json or json_pretty, default is plain) | yes | no | no | 'plain'` |
## talk:monitor:calls
Prints a list with conversations that have an active call as well as their participant count

3
lib/Command/Command/Add.php

@ -40,6 +40,7 @@ class Add extends Base {
}
protected function configure(): void {
parent::configure();
$this
->setName('talk:command:add')
->setDescription('Add a new command')
@ -110,7 +111,7 @@ class Add extends Base {
$output->writeln('<info>Command added</info>');
$output->writeln('');
$this->renderCommands(Base::OUTPUT_FORMAT_PLAIN, $output, [$command]);
$this->renderCommands($input, $output, [$command]);
$output->writeln('');
$output->writeln("<comment>If you think your command makes sense for other users as well, feel free to share it in the following github issue:\n https://github.com/nextcloud/spreed/issues/1566</comment>");

2
lib/Command/Command/AddSamples.php

@ -107,7 +107,7 @@ class AddSamples extends Base {
$output->writeln('<info>Commands added</info>');
$output->writeln('');
$this->renderCommands(Base::OUTPUT_FORMAT_PLAIN, $output, $this->commands);
$this->renderCommands($input, $output, $this->commands);
return 0;
}

2
lib/Command/Command/ListCommand.php

@ -57,7 +57,7 @@ class ListCommand extends Base {
$commands = $this->service->findByApp($app === 'custom' ? '' : $app);
}
$this->renderCommands($input->getOption('output'), $output, $commands, true);
$this->renderCommands($input, $output, $commands, true);
return 0;
}
}

6
lib/Command/Command/TRenderCommand.php

@ -26,15 +26,17 @@ namespace OCA\Talk\Command\Command;
use OC\Core\Command\Base;
use OCA\Talk\Model\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
trait TRenderCommand {
protected function renderCommands(string $outputFormat, OutputInterface $output, array $commands, bool $showHelp = false): void {
protected function renderCommands(InputInterface $input, OutputInterface $output, array $commands, bool $showHelp = false): void {
$result = array_map(function (Command $command) {
return $command->asArray();
}, $commands);
if ($outputFormat === Base::OUTPUT_FORMAT_PLAIN) {
$plainText = $input->getOption('output') ?? Base::OUTPUT_FORMAT_PLAIN;
if ($plainText === Base::OUTPUT_FORMAT_PLAIN) {
if ($showHelp) {
$output->writeln('Response values: 0 - No one, 1 - User, 2 - All');
$output->writeln('Enabled values: 0 - Disabled, 1 - Moderators, 2 - Users, 3 - Guests');

3
lib/Command/Command/Update.php

@ -41,6 +41,7 @@ class Update extends Base {
}
protected function configure(): void {
parent::configure();
$this
->setName('talk:command:update')
->setDescription('Add a new command')
@ -119,7 +120,7 @@ class Update extends Base {
$output->writeln('<info>Command updated</info>');
$output->writeln('');
$this->renderCommands(Base::OUTPUT_FORMAT_PLAIN, $output, [$command]);
$this->renderCommands($input, $output, [$command]);
return 0;
}
}

1
tests/integration/features/bootstrap/CommandLineTrait.php

@ -148,6 +148,7 @@ trait CommandLineTrait {
}
/**
* @Then /^the command output contains the text:$/
* @Then /^the command output contains the text "([^"]*)"$/
*/
public function theCommandOutputContainsTheText($text) {

24
tests/integration/features/command/command-list.feature

@ -0,0 +1,24 @@
Feature: command/command-list
Scenario: Get the output options
Given invoking occ with "talk:command:list --help"
Then the command was successful
And the command output contains the text "Output format"
Scenario: List all available commands as plain text and verify if contains the help command as markdown table (default)
Given invoking occ with "talk:command:list"
Then the command was successful
And the command output contains the text "| help"
Scenario: List all available commands as plain text and verify if contains the help command as markdown table
Given invoking occ with "talk:command:list --output=plain"
Then the command was successful
And the command output contains the text "| help"
Scenario: List all available commands as json and verify if contains the help command as json format
Given invoking occ with "talk:command:list --output=json"
Then the command was successful
And the command output contains the text:
"""
"name":"talk","command":"help","script":"help"
"""
Loading…
Cancel
Save