Skip to content

Commit

Permalink
Add fs:symlink command
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfaassen committed Sep 26, 2016
1 parent 4ba8d12 commit cb5403e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Command/FsSymlinkCommand.php
@@ -0,0 +1,54 @@
<?php
namespace Droid\Plugin\Fs\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Droid\Lib\Plugin\Command\CheckableTrait;
use RuntimeException;

class FsSymlinkCommand extends Command
{
use CheckableTrait;

public function configure()
{
$this->setName('fs:symlink')
->setDescription('Make a symbolic link')
->addArgument(
'src',
InputArgument::REQUIRED,
'Source'
)
->addArgument(
'dest',
InputArgument::REQUIRED,
'Destination filename'
)
;
$this->configureCheckMode();
}

public function execute(InputInterface $input, OutputInterface $output)
{
$src = $input->getArgument('src');
$dest = $input->getArgument('dest');
$this->activateCheckMode($input);

if (!file_exists($dest)) {
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
$output->writeln('Destination does not yet exist');
}
$this->markChange();

if (!$this->checkMode()) {
if (!symlink($src, $dest)) {
throw new RuntimeException("Symlink failed: " . $src . ' to ' . $dest);
}
}
}
$this->reportChange($output);
}
}
1 change: 1 addition & 0 deletions src/DroidPlugin.php
Expand Up @@ -45,6 +45,7 @@ public function getCommands()
new LineFactory(NameValueLine::class)
)
);
$commands[] = new \Droid\Plugin\Fs\Command\FsSymlinkCommand();
$commands[] = new \Droid\Plugin\Fs\Command\FsTemplateCommand();
$commands[] = new \Droid\Plugin\Fs\Command\FsTouchCommand();
return $commands;
Expand Down

0 comments on commit cb5403e

Please sign in to comment.