Example #1
0
 /**
  * Execute command
  *
  * @param  InputInterface  $input  Input instance
  * @param  OutputInterface $output Output instance
  *
  * @return int|null|void
  * @throws \Exception
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $cliSyncFilePath = getcwd() . '/' . AbstractCommand::CONFIG_FILE;
     if (file_exists($cliSyncFilePath)) {
         $this->output->writeln('<p-error>Configuration file ' . AbstractCommand::CONFIG_FILE . ' already exists</p-error>');
         return 1;
     }
     // fetch example
     $content = PhpUtility::fileGetContents(CLITOOLS_ROOT_FS . '/conf/clisync.yml');
     // store in current working dir
     PhpUtility::filePutContents($cliSyncFilePath, $content);
     // Start editor with file (if $EDITOR is set)
     try {
         $editor = new EditorCommandBuilder();
         $editor->addArgument($cliSyncFilePath)->executeInteractive();
     } catch (\Exception $e) {
         $this->output->writeln('<p-error>' . $e->getMessage() . '</p-error>');
     }
     $this->output->writeln('<info>Successfully created ' . AbstractCommand::CONFIG_FILE . ' </info>');
 }
Example #2
0
 /**
  * Start interactive editor
  *
  * @param string $path Path to file
  */
 protected function startInteractiveEditor($path)
 {
     if (file_exists($path)) {
         // Start editor with file (if $EDITOR is set)
         try {
             $editor = new EditorCommandBuilder();
             $this->setTerminalTitle('Edit', basename($path));
             $this->output->writeln('<h2>Starting interactive EDITOR for file ' . $path . '</h2>');
             sleep(1);
             $editor->addArgument($path)->executeInteractive();
         } catch (\Exception $e) {
             $this->addFinishMessage('<p-error>' . $e->getMessage() . '</p-error>');
         }
     }
 }