这是indexloc提供的服务,不要输入任何密码
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
16 changes: 16 additions & 0 deletions src/Cli/Command/DefaultTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace Zalas\Toolbox\Cli\Command;

trait DefaultTag
{
private function defaultExcludeTag(): array
{
return \getenv('TOOLBOX_EXCLUDED_TAGS') ? \explode(',', \getenv('TOOLBOX_EXCLUDED_TAGS')) : [\sprintf('exclude-php:%s.%s', PHP_MAJOR_VERSION, PHP_MINOR_VERSION)];
}

private function defaultTag(): array
{
return \getenv('TOOLBOX_TAGS') ? \explode(',', \getenv('TOOLBOX_TAGS')) : [];
}
}
5 changes: 3 additions & 2 deletions src/Cli/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

final class InstallCommand extends Command
{
use DefaultTag;
use DefaultTargetDir;

public const NAME = 'install';
Expand All @@ -32,8 +33,8 @@ protected function configure()
$this->setDescription('Installs tools');
$this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Output the command without executing it');
$this->addOption('target-dir', null, InputOption::VALUE_REQUIRED, 'The target installation directory', $this->defaultTargetDir());
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude');
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by');
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude', $this->defaultExcludeTag());
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by', $this->defaultTag());
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down
6 changes: 4 additions & 2 deletions src/Cli/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

final class ListCommand extends Command
{
use DefaultTag;

public const NAME = 'list-tools';

private $listTools;
Expand All @@ -28,8 +30,8 @@ public function __construct(ListTools $listTools)
protected function configure()
{
$this->setDescription('Lists available tools');
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude');
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by');
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude', $this->defaultExcludeTag());
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by', $this->defaultTag());
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down
5 changes: 3 additions & 2 deletions src/Cli/Command/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

final class TestCommand extends Command
{
use DefaultTag;
use DefaultTargetDir;

public const NAME = 'test';
Expand All @@ -32,8 +33,8 @@ protected function configure()
$this->setDescription('Runs basic tests to verify tools are installed');
$this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Output the command without executing it');
$this->addOption('target-dir', null, InputOption::VALUE_REQUIRED, 'The target installation directory', $this->defaultTargetDir());
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude');
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by');
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude', $this->defaultExcludeTag());
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by', $this->defaultTag());
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down
18 changes: 18 additions & 0 deletions tests/Cli/Command/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,29 @@ public function test_it_takes_the_target_dir_option_default_from_environment_if_
public function test_it_defines_exclude_tag_option()
{
$this->assertTrue($this->cliCommand()->getDefinition()->hasOption('exclude-tag'));
$this->assertSame([\sprintf('exclude-php:%s.%s', PHP_MAJOR_VERSION, PHP_MINOR_VERSION)], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault());
}

/**
* @putenv TOOLBOX_EXCLUDED_TAGS=foo,bar,baz
*/
public function test_it_takes_the_excluded_tag_option_default_from_environment_if_present()
{
$this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault());
}

public function test_it_defines_tag_option()
{
$this->assertTrue($this->cliCommand()->getDefinition()->hasOption('tag'));
$this->assertSame([], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault());
}

/**
* @putenv TOOLBOX_TAGS=foo,bar,baz
*/
public function test_it_takes_the_tag_option_default_from_environment_if_present()
{
$this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault());
}

protected function getContainerTestDoubles(): array
Expand Down
17 changes: 17 additions & 0 deletions tests/Cli/Command/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,30 @@ public function test_it_filters_by_tags()
public function test_it_defines_exclude_tag_option()
{
$this->assertTrue($this->cliCommand()->getDefinition()->hasOption('exclude-tag'));
$this->assertSame([\sprintf('exclude-php:%s.%s', PHP_MAJOR_VERSION, PHP_MINOR_VERSION)], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault());
}

/**
* @putenv TOOLBOX_EXCLUDED_TAGS=foo,bar,baz
*/
public function test_it_takes_the_excluded_tag_option_default_from_environment_if_present()
{
$this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault());
}

public function test_it_defines_tag_option()
{
$this->assertTrue($this->cliCommand()->getDefinition()->hasOption('tag'));
}

/**
* @putenv TOOLBOX_TAGS=foo,bar,baz
*/
public function test_it_takes_the_tag_option_default_from_environment_if_present()
{
$this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault());
}

protected function getContainerTestDoubles(): array
{
return [
Expand Down
17 changes: 17 additions & 0 deletions tests/Cli/Command/TestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,30 @@ public function test_it_takes_the_target_dir_option_default_from_environment_if_
public function test_it_defines_exclude_tag_option()
{
$this->assertTrue($this->cliCommand()->getDefinition()->hasOption('exclude-tag'));
$this->assertSame([\sprintf('exclude-php:%s.%s', PHP_MAJOR_VERSION, PHP_MINOR_VERSION)], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault());
}

/**
* @putenv TOOLBOX_EXCLUDED_TAGS=foo,bar,baz
*/
public function test_it_takes_the_excluded_tag_option_default_from_environment_if_present()
{
$this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault());
}

public function test_it_defines_tag_option()
{
$this->assertTrue($this->cliCommand()->getDefinition()->hasOption('tag'));
}

/**
* @putenv TOOLBOX_TAGS=foo,bar,baz
*/
public function test_it_takes_the_tag_option_default_from_environment_if_present()
{
$this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault());
}

protected function getContainerTestDoubles(): array
{
return [
Expand Down