Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/occ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|---|---|---|---|---|
Expand All @@ -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, …
Expand Down Expand Up @@ -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 |
|---|---|---|---|---|
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/Command/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct(CommandService $service) {
}

protected function configure(): void {
parent::configure();
$this
->setName('talk:command:add')
->setDescription('Add a new command')
Expand Down Expand Up @@ -110,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$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>");
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Command/AddSamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$commands = $this->service->findByApp($app === 'custom' ? '' : $app);
}

$this->renderCommands($input->getOption('output'), $output, $commands, true);
$this->renderCommands($input, $output, $commands, true);
return 0;
}
}
6 changes: 4 additions & 2 deletions lib/Command/Command/TRenderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
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');
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/Command/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(CommandService $service) {
}

protected function configure(): void {
parent::configure();
$this
->setName('talk:command:update')
->setDescription('Add a new command')
Expand Down Expand Up @@ -119,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln('<info>Command updated</info>');
$output->writeln('');
$this->renderCommands(Base::OUTPUT_FORMAT_PLAIN, $output, [$command]);
$this->renderCommands($input, $output, [$command]);
return 0;
}
}
1 change: 1 addition & 0 deletions tests/integration/features/bootstrap/CommandLineTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function theCommandFailedWithException($exceptionText) {
}

/**
* @Then /^the command output contains the text:$/
* @Then /^the command output contains the text "([^"]*)"$/
*/
public function theCommandOutputContainsTheText($text) {
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/features/command/command-list.feature
Original file line number Diff line number Diff line change
@@ -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"
"""