Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Apr 11, 2022
1 parent b368b4e commit b31a099
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 46 deletions.
18 changes: 9 additions & 9 deletions demo/Commands/ExamplesAgruments.php
Expand Up @@ -164,31 +164,31 @@ protected function executeAction(): int
// ./my-app examples:agruments -aQwerty -aAsd
$this->getOpt('opt-array-req-default'); // 'Asd'


$input = $this->helper->getInput();
////////////////////////////////////////// Arguments
// ./my-app examples:agruments
$this->input->getArgument('arg-req'); // null
$input->getArgument('arg-req'); // null

// ./my-app examples:agruments Qwerty
$this->input->getArgument('arg-req'); // "Qwerty"
$input->getArgument('arg-req'); // "Qwerty"

// ./my-app examples:agruments Qwerty
$this->input->getArgument('arg-default'); // 42
$input->getArgument('arg-default'); // 42

// ./my-app examples:agruments Qwerty Some text
$this->input->getArgument('arg-default'); // "Some"
$input->getArgument('arg-default'); // "Some"

// ./my-app examples:agruments Qwerty "Some text"
$this->input->getArgument('arg-default'); // "Some text"
$input->getArgument('arg-default'); // "Some text"

// ./my-app examples:agruments Qwerty "Some text"
$this->input->getArgument('arg-optional'); // []
$input->getArgument('arg-optional'); // []

// ./my-app examples:agruments Qwerty "Some text" 123
$this->input->getArgument('arg-optional'); // ["123"]
$input->getArgument('arg-optional'); // ["123"]

// ./my-app examples:agruments Qwerty "Some text" 123 456 "789 098"
$this->input->getArgument('arg-optional'); // ["123", "456", "789 098"]
$input->getArgument('arg-optional'); // ["123", "456", "789 098"]


////////////////////////////////////////// Standard input
Expand Down
3 changes: 1 addition & 2 deletions demo/my-app
Expand Up @@ -24,6 +24,5 @@ require_once dirname(__DIR__) . '/vendor/autoload.php';

$application = new CliApplication('Example CLI Application', 'v1.0.0');
$application->registerCommandsByPath(__DIR__ . '/Commands', __NAMESPACE__);
// $application->setDefaultCommand('simple');

$application->setDefaultCommand('list');
$application->run();
31 changes: 5 additions & 26 deletions src/CliCommand.php
Expand Up @@ -22,7 +22,6 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

use function JBZoo\Utils\bool;
Expand All @@ -39,24 +38,7 @@ abstract class CliCommand extends Command
* @var Helper
* @psalm-suppress PropertyNotSetInConstructor
*/
private $helper;

/**
* @var InputInterface
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $input;

/**
* @var OutputInterface|ConsoleOutput
* @psalm-suppress PropertyNotSetInConstructor
*/
protected $output;

/**
* @var OutputInterface
*/
protected $errOutput;
protected $helper;

/**
* @inheritDoc
Expand Down Expand Up @@ -91,9 +73,6 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->helper = new Helper($input, $output);
$this->input = $this->helper->getInput();
$this->output = $this->helper->getOutput();
$this->errOutput = $this->helper->getErrOutput();

$exitCode = 0;
try {
Expand Down Expand Up @@ -148,7 +127,7 @@ abstract protected function executeAction(): int;
*/
protected function getOpt(string $optionName, bool $canBeArray = true)
{
$value = $this->input->getOption($optionName);
$value = $this->helper->getInput()->getOption($optionName);

if ($canBeArray && \is_array($value)) {
return Arr::last($value);
Expand Down Expand Up @@ -259,23 +238,23 @@ protected function _($messages = '', string $verboseLevel = ''): void
*/
protected function isInfoLevel(): bool
{
return $this->output->isVerbose();
return $this->helper->getOutput()->isVerbose();
}

/**
* @return bool
*/
protected function isWarningLevel(): bool
{
return $this->output->isVeryVerbose();
return $this->helper->getOutput()->isVeryVerbose();
}

/**
* @return bool
*/
protected function isDebugLevel(): bool
{
return $this->output->isDebug();
return $this->helper->getOutput()->isDebug();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/CliCommandMultiProc.php
Expand Up @@ -146,7 +146,7 @@ protected function executeMultiProcessAction(): int
$procListIds = $this->getListOfChildIds();

if (!$this->getOptBool('no-progress')) {
$this->progressBar = new ProgressBarProcessManager($this->output, \count($procListIds));
$this->progressBar = new ProgressBarProcessManager($this->helper->getOutput(), \count($procListIds));
$this->progressBar->start();
}

Expand Down Expand Up @@ -234,7 +234,7 @@ private function initProcManager(
private function createSubProcess(string $procId): Process
{
// Prepare option list from the parent process
$options = \array_filter($this->input->getOptions(), static function ($optionValue): bool {
$options = \array_filter($this->helper->getInput()->getOptions(), static function ($optionValue): bool {
return $optionValue !== false && $optionValue !== '';
});

Expand All @@ -250,7 +250,7 @@ private function createSubProcess(string $procId): Process
$options['pm-proc-id'] = $procId;

// Prepare $argument list from the parent process
$arguments = $this->input->getArguments();
$arguments = $this->helper->getInput()->getArguments();
$argumentsList = [];

foreach ($arguments as $argKey => $argValue) {
Expand Down
2 changes: 1 addition & 1 deletion tests/fake-app/Commands/TestCliOptions.php
Expand Up @@ -71,7 +71,7 @@ protected function executeAction(): int

foreach ($options as $option) {
$result[$option] = [
'Default' => $this->input->getOption($option),
'Default' => $this->helper->getInput()->getOption($option),
'Bool' => $this->getOptBool($option),
'Int' => $this->getOptInt($option),
'Float' => $this->getOptFloat($option),
Expand Down
4 changes: 2 additions & 2 deletions tests/fake-app/Commands/TestProgress.php
Expand Up @@ -167,8 +167,8 @@ protected function executeAction(): int

if ($testCase === 'nested') {
$array = [];
$parentSection = $this->output->section();
$childSection = $this->output->section();
$parentSection = $this->helper->getOutput()->section();
$childSection = $this->helper->getOutput()->section();

ProgressBar::run(3, function ($parentId) use ($testCase, $childSection) {
sleep($this->getOptInt('sleep'));
Expand Down
6 changes: 3 additions & 3 deletions tests/fake-app/Commands/TestSleepMulti.php
Expand Up @@ -65,9 +65,9 @@ protected function executeOneProcess(string $pmThreadId): int
$this->_([
"Started: {$pmThreadId}",
'Sleep : ' . $sleep,
'Arg #1: ' . $this->input->getArgument('arg-1'),
'Arg #2: ' . $this->input->getArgument('arg-2'),
'Arg #3: ' . $this->input->getArgument('arg-3'),
'Arg #1: ' . $this->helper->getInput()->getArgument('arg-1'),
'Arg #2: ' . $this->helper->getInput()->getArgument('arg-2'),
'Arg #3: ' . $this->helper->getInput()->getArgument('arg-3'),
'Env Var: ' . Env::string('JBZOO_TEST_VAR'),
]);

Expand Down

0 comments on commit b31a099

Please sign in to comment.