Skip to content

Commit

Permalink
remove SymfonyStyle to make it compatible with symfony console versio…
Browse files Browse the repository at this point in the history
…n used on Magento2
  • Loading branch information
jalogut committed Mar 6, 2017
1 parent 3373578 commit cf792f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
14 changes: 7 additions & 7 deletions src/Staempfli/Symlinker/Command/Create/AbstractCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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('<question>File Path:</question>');
$fileInput = $this->questionHelper->ask($input, $output, $question);
$input->setArgument(self::ARG_FILE_PATH, $fileInput);
}
}
Expand All @@ -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('<bg=green;options=bold>Symlinks successfully created!</>');
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Staempfli/Symlinker/Command/Create/CreateLinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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('<question>Source Path:</question>');
$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('<question>Destination Path:</question>');
$destInput = $this->questionHelper->ask($input, $output, $question);
$input->setArgument(self::ARG_DESTINATION, $destInput);
}
}
Expand All @@ -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('<bg=green;options=bold>Symlink successfully created!</>');
}
}
8 changes: 3 additions & 5 deletions src/Staempfli/Symlinker/Command/Phar/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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('<bg=green;options=bold>Updated to version %s from %s</>', $newVersion, $oldVersion));
} else {
$symfonyStyle->writeln('<info>No update needed!</info>');
$output->writeln('<info>No update needed!</info>');
}
} catch (\Exception $e) {
$symfonyStyle->error('There was an error while updating. Please try again later');
$output->error('<error>There was an error while updating. Please try again later</error>');
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Staempfli/Symlinker/Task/SymlinkTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -27,9 +27,9 @@ class SymlinkTask
*/
protected $relativeTargetHelper;
/**
* @var SymfonyStyle
* @var OutputInterface
*/
protected $symfonyStyle;
protected $consoleOutput;
/**
* @var string
*/
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}
}

Expand Down

0 comments on commit cf792f5

Please sign in to comment.