diff --git a/src/Staempfli/Symlinker/Command/Create/AbstractCreateCommand.php b/src/Staempfli/Symlinker/Command/Create/AbstractCreateCommand.php index 927c2e3..7008b4d 100644 --- a/src/Staempfli/Symlinker/Command/Create/AbstractCreateCommand.php +++ b/src/Staempfli/Symlinker/Command/Create/AbstractCreateCommand.php @@ -10,10 +10,10 @@ use Staempfli\Symlinker\Task\SymlinkTask; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; abstract class AbstractCreateCommand extends Command { @@ -22,14 +22,14 @@ abstract class AbstractCreateCommand extends Command const OPTION_DRY_RUN = 'dry-run'; const OPTION_ENABLE_WILDCARDS = 'enable-wildcards'; - /** - * @var SymfonyStyle - */ - protected $symfonyStyle; /** * @var SymlinkTask */ protected $symlinkTask; + /** + * @var QuestionHelper + */ + protected $questionHelper; public function __construct($name = null) { @@ -67,8 +67,8 @@ protected function configure() */ public function run(InputInterface $input, OutputInterface $output) { - $this->symfonyStyle = new SymfonyStyle($input, $output); - $this->symlinkTask->setSymfonyStyle($this->symfonyStyle); + $this->questionHelper = $this->getHelper('question'); + $this->symlinkTask->setConsoleOutput($output); return parent::run($input, $output); } diff --git a/src/Staempfli/Symlinker/Command/Create/CreateFromFileCommand.php b/src/Staempfli/Symlinker/Command/Create/CreateFromFileCommand.php index f17997c..7529e5c 100644 --- a/src/Staempfli/Symlinker/Command/Create/CreateFromFileCommand.php +++ b/src/Staempfli/Symlinker/Command/Create/CreateFromFileCommand.php @@ -14,6 +14,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\Question; class CreateFromFileCommand extends AbstractCreateCommand { @@ -56,7 +57,8 @@ protected function interact(InputInterface $input, OutputInterface $output) { parent::interact($input, $output); if (!$input->getArgument(self::ARG_FILE_PATH)) { - $fileInput = $this->symfonyStyle->ask('File Path:'); + $question = new Question('File Path:'); + $fileInput = $this->questionHelper->ask($input, $output, $question); $input->setArgument(self::ARG_FILE_PATH, $fileInput); } } @@ -74,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $dest = $this->getDestPathWithPrefixAppended($dest, $input); $this->symlinkTask->createSymlink($source, $dest); } - $this->symfonyStyle->success('Symlinks successfully created!'); + $output->writeln('Symlinks successfully created!'); } /** diff --git a/src/Staempfli/Symlinker/Command/Create/CreateLinkCommand.php b/src/Staempfli/Symlinker/Command/Create/CreateLinkCommand.php index ae64c65..e7c5f2b 100644 --- a/src/Staempfli/Symlinker/Command/Create/CreateLinkCommand.php +++ b/src/Staempfli/Symlinker/Command/Create/CreateLinkCommand.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\Question; class CreateLinkCommand extends AbstractCreateCommand { @@ -42,11 +43,13 @@ protected function interact(InputInterface $input, OutputInterface $output) parent::interact($input, $output); if (!$input->getArgument(self::ARG_SOURCE)) { - $sourceInput = $this->symfonyStyle->ask('Source Path:'); + $question = new Question('Source Path:'); + $sourceInput = $this->questionHelper->ask($input, $output, $question); $input->setArgument(self::ARG_SOURCE, $sourceInput); } if (!$input->getArgument(self::ARG_DESTINATION)) { - $destInput = $this->symfonyStyle->ask('Destination Path:'); + $question = new Question('Destination Path:'); + $destInput = $this->questionHelper->ask($input, $output, $question); $input->setArgument(self::ARG_DESTINATION, $destInput); } } @@ -62,6 +65,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $dest = $input->getArgument(self::ARG_DESTINATION); $this->symlinkTask->createSymlink($source, $dest); - $this->symfonyStyle->success('Symlink successfully created!'); + $output->writeln('Symlink successfully created!'); } } \ No newline at end of file diff --git a/src/Staempfli/Symlinker/Command/Phar/SelfUpdateCommand.php b/src/Staempfli/Symlinker/Command/Phar/SelfUpdateCommand.php index 492766d..88a1f8c 100644 --- a/src/Staempfli/Symlinker/Command/Phar/SelfUpdateCommand.php +++ b/src/Staempfli/Symlinker/Command/Phar/SelfUpdateCommand.php @@ -13,7 +13,6 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; class SelfUpdateCommand extends Command { @@ -72,18 +71,17 @@ protected function execute(InputInterface $input, OutputInterface $output) $updater->getStrategy()->setPharName('symlinker-pro.phar'); $updater->getStrategy()->setCurrentLocalVersion('@git-version@'); - $symfonyStyle = new SymfonyStyle($input, $output); try { $result = $updater->update(); if ($result) { $newVersion = $updater->getNewVersion(); $oldVersion = $updater->getOldVersion(); - $symfonyStyle->success(sprintf('Updated to version %s from %s', $newVersion, $oldVersion)); + $output->success(sprintf('Updated to version %s from %s', $newVersion, $oldVersion)); } else { - $symfonyStyle->writeln('No update needed!'); + $output->writeln('No update needed!'); } } catch (\Exception $e) { - $symfonyStyle->error('There was an error while updating. Please try again later'); + $output->error('There was an error while updating. Please try again later'); } } diff --git a/src/Staempfli/Symlinker/Task/SymlinkTask.php b/src/Staempfli/Symlinker/Task/SymlinkTask.php index c6a635f..a6dc9cc 100644 --- a/src/Staempfli/Symlinker/Task/SymlinkTask.php +++ b/src/Staempfli/Symlinker/Task/SymlinkTask.php @@ -10,7 +10,7 @@ use Staempfli\Symlinker\Helper\FileHelper; use Staempfli\Symlinker\Helper\RelativeTargetHelper; use Staempfli\Symlinker\Helper\SourcePathHelper; -use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Console\Output\OutputInterface; class SymlinkTask { @@ -27,9 +27,9 @@ class SymlinkTask */ protected $relativeTargetHelper; /** - * @var SymfonyStyle + * @var OutputInterface */ - protected $symfonyStyle; + protected $consoleOutput; /** * @var string */ @@ -62,11 +62,11 @@ public function __construct() } /** - * @param SymfonyStyle $symfonyStyle + * @param OutputInterface $consoleOutput */ - public function setSymfonyStyle(SymfonyStyle $symfonyStyle) + public function setConsoleOutput(OutputInterface $consoleOutput) { - $this->symfonyStyle = $symfonyStyle; + $this->consoleOutput = $consoleOutput; } public function enableWildcards() @@ -174,7 +174,7 @@ protected function createRelativeTargetLink($target, $link) throw new \Exception(sprintf('There was an error creating symlink %s -> %s', $relativeTarget, $link)); } } - $this->symfonyStyle->writeln(sprintf('- Symlink Created: %s -> %s', $relativeTarget, $link)); + $this->consoleOutput->writeln(sprintf('- Symlink Created: %s -> %s', $relativeTarget, $link)); } /** @@ -204,7 +204,7 @@ protected function prepareDestination($link) throw new \Exception(sprintf('Destination exists: %s. Use --force to overwrite', $link)); } $this->fileHelper->removeExitingPath($link); - $this->symfonyStyle->writeln(sprintf('- Path removed: %s', $link)); + $this->consoleOutput->writeln(sprintf('- Path removed: %s', $link)); } }