-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
335 additions
and
28 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
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,22 @@ | ||
<?php | ||
|
||
namespace LF\EnvDiff\Console; | ||
|
||
use LF\EnvDiff\Console\Command\ActualizeCommand; | ||
use LF\EnvDiff\Console\Command\DiffCommand; | ||
use Symfony\Component\Console\Application as BaseApplication; | ||
|
||
class Application extends BaseApplication | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct('Env diff', '1.0.0'); | ||
|
||
$this->setAutoExit(true); | ||
$this->add(new DiffCommand('diff')); | ||
$this->add(new ActualizeCommand('actualize')); | ||
} | ||
} |
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,69 @@ | ||
<?php | ||
|
||
namespace LF\EnvDiff\Console\Command; | ||
|
||
use LF\EnvDiff\Config; | ||
use LF\EnvDiff\IO\ConsoleIO; | ||
use LF\EnvDiff\Processor; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
abstract class AbstractCommand extends Command | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->addArgument('dist', InputOption::VALUE_REQUIRED, 'From file', Config::DEFAULT_DIST) | ||
->addArgument('target', InputOption::VALUE_REQUIRED, 'To file', Config::DEFAULT_TARGET) | ||
->addOption('keep-outdated', 'k', InputOption::VALUE_OPTIONAL, 'Keep old env variables', true); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$config = $this->createConfig($input); | ||
$processor = $this->createProcessor($input, $output); | ||
|
||
$this->doExecute($processor, $config); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* | ||
* @return Config | ||
*/ | ||
private function createConfig(InputInterface $input) | ||
{ | ||
$dist = $input->getArgument('dist'); | ||
$target = $input->getArgument('target'); | ||
$keepOutdated = $input->getOption('keep-outdated'); | ||
|
||
return new Config($dist, $target, $keepOutdated); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* | ||
* @return Processor | ||
*/ | ||
private function createProcessor(InputInterface $input, OutputInterface $output) | ||
{ | ||
return new Processor(new ConsoleIO($input, $output)); | ||
} | ||
|
||
/** | ||
* @param Processor $processor | ||
* @param Config $config | ||
*/ | ||
abstract protected function doExecute(Processor $processor, Config $config); | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace LF\EnvDiff\Console\Command; | ||
|
||
use LF\EnvDiff\Config; | ||
use LF\EnvDiff\Processor; | ||
|
||
class ActualizeCommand extends AbstractCommand | ||
{ | ||
/** | ||
* @param Processor $processor | ||
* @param Config $config | ||
*/ | ||
protected function doExecute(Processor $processor, Config $config) | ||
{ | ||
$processor->actualizeEnv($config); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace LF\EnvDiff\Console\Command; | ||
|
||
use LF\EnvDiff\Config; | ||
use LF\EnvDiff\Processor; | ||
|
||
class DiffCommand extends AbstractCommand | ||
{ | ||
/** | ||
* @param Processor $processor | ||
* @param Config $config | ||
*/ | ||
protected function doExecute(Processor $processor, Config $config) | ||
{ | ||
$processor->showDifference($config); | ||
} | ||
} |
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
Oops, something went wrong.