From cb5403e0e304535bee3d20a2c062ce47bc2bdbcd Mon Sep 17 00:00:00 2001 From: "j.faassen" Date: Mon, 26 Sep 2016 22:01:56 +0200 Subject: [PATCH] Add fs:symlink command --- src/Command/FsSymlinkCommand.php | 54 ++++++++++++++++++++++++++++++++ src/DroidPlugin.php | 1 + 2 files changed, 55 insertions(+) create mode 100644 src/Command/FsSymlinkCommand.php diff --git a/src/Command/FsSymlinkCommand.php b/src/Command/FsSymlinkCommand.php new file mode 100644 index 0000000..b5671b4 --- /dev/null +++ b/src/Command/FsSymlinkCommand.php @@ -0,0 +1,54 @@ +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); + } +} diff --git a/src/DroidPlugin.php b/src/DroidPlugin.php index 331c2dc..6d4facc 100644 --- a/src/DroidPlugin.php +++ b/src/DroidPlugin.php @@ -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;