Created
July 10, 2020 04:00
-
-
Save biplobice/cd5873b6c4ac0e18a220f9ea3fe8304e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Concrete\Console\Command; | |
use Concrete\Core\Console\Command; | |
use Concrete\Core\Error\UserMessageException; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Input\InputOption; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class MyCommand extends Command | |
{ | |
protected function configure() | |
{ | |
$errExitCode = static::RETURN_CODE_ON_FAILURE; | |
$this | |
->setName('c5:my:command') | |
->setDescription('My command description') | |
->addEnvOption() | |
->addOption('option-a', 'a', InputOption::VALUE_REQUIRED, 'Option a description') | |
->addOption('option-b', 'b', InputOption::VALUE_REQUIRED, 'Option b description') | |
->setHelp(<<<EOT | |
You can use this as a command template. | |
To do task a, use the option a. | |
To do task b, use the option b. | |
Returns codes: | |
0 operation completed successfully | |
$errExitCode errors occurred | |
More info at http://documentation.concrete5.org/developers/appendix/cli-commands | |
EOT | |
) | |
; | |
} | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
// Input | |
$optionA = $input->getOption('option-a'); | |
$optionB = $input->getOption('option-b'); | |
// Output | |
$output->write('Output message here'); | |
// Error | |
if ($isError) { | |
throw new UserMessageException('Error message here'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment