-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to list available features
console progressive:features Available: dark-theme light-theme homepage-v2 console progressive:features homepage-v2 Name: homepage-v2 Config: unanimous: roles: ROLE-DEV env: dev, preprod
- Loading branch information
Showing
11 changed files
with
318 additions
and
4,876 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/vendor/ | ||
.php_cs.cache | ||
composer.lock | ||
.phpunit.xml | ||
.phpunit.result.cache | ||
.php_cs.cache |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Af\ProgressiveBundle\Command; | ||
|
||
use Progressive\Progressive; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class ListFeaturesCommand extends Command | ||
{ | ||
private $progressive; | ||
protected static $defaultName = 'progressive:features'; | ||
|
||
public function __construct(Progressive $progressive) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->progressive = $progressive; | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setDescription('List the available features.') | ||
->setHelp( | ||
<<<'EOF' | ||
The <info>%command.name%</info> command lists all the features defined in Progressive: | ||
<info>php %command.full_name%</info> | ||
You can also display the feature's configuration: | ||
<info>php %command.full_name% feature-name</info> | ||
EOF | ||
) | ||
->addArgument('feature', InputArgument::OPTIONAL, "The feature's name") | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$feature = $input->getArgument('feature'); | ||
|
||
return $feature ? | ||
$this->describeFeature($output, $feature) : | ||
$this->describeAll($output); | ||
} | ||
|
||
private function describeAll(OutputInterface $output) | ||
{ | ||
$output->writeln('<comment>Available features:</comment>'); | ||
|
||
foreach ($this->progressive->all() as $feature => $config) { | ||
$output->writeln(sprintf(' <info>%s</info>', $feature)); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
private function describeFeature(OutputInterface $output, string $feature) | ||
{ | ||
$config = $this->progressive->all(); | ||
|
||
if (!array_key_exists($feature, $config)) { | ||
return Command::FAILURE; | ||
} | ||
|
||
$config = $config[$feature]; | ||
// Short syntax | ||
if (is_bool($config)) { | ||
$config = ['enabled' => $config]; | ||
} | ||
|
||
$output->writeln('<comment>Name:</comment>'); | ||
$output->writeln(sprintf(' %s%s', $feature, PHP_EOL)); | ||
|
||
$output->writeln('<comment>Config:</comment>'); | ||
|
||
return $this->describeConfig($output, $config); | ||
} | ||
|
||
private function describeConfig(OutputInterface $output, array $config, int $level = 1) | ||
{ | ||
foreach ($config as $key => $values) { | ||
$output->write(sprintf('%s<info>%s:</info>', str_repeat(' ', $level * 2), $key)); | ||
|
||
if (is_array($values)) { | ||
if (!is_int(key($values))) { | ||
$output->writeln(''); | ||
$this->describeConfig($output, $values, ++$level); | ||
--$level; | ||
continue; | ||
} | ||
|
||
$values = implode(', ', $values); | ||
} | ||
|
||
$output->writeln(sprintf(' %s', $values)); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="Af\ProgressiveBundle\Command\ListFeaturesCommand"> | ||
<argument type="service" id="Progressive\Progressive"/> | ||
<tag name="console.command"/> | ||
</service> | ||
</services> | ||
</container> |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="Af\ProgressiveBundle\Twig\ProgressiveExtension"> | ||
<argument type="service" id="Progressive\Progressive"/> | ||
<tag name="twig.extension"/> | ||
</service> | ||
</services> | ||
</container> |
This file contains 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
Oops, something went wrong.