Esempio n. 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>');
 }
Esempio n. 2
0
 /**
  * Read and validate configuration
  */
 protected function readConfiguration()
 {
     $this->config = new ConfigReader();
     if (empty($this->confArea)) {
         throw new \RuntimeException('Config area not set, cannot continue');
     }
     if (!file_exists($this->confFilePath)) {
         throw new \RuntimeException('Config file "' . $this->confFilePath . '" not found');
     }
     $conf = Yaml::parse(PhpUtility::fileGetContents($this->confFilePath));
     // Switch to area configuration
     if (!empty($conf)) {
         $this->config->setData($conf);
     } else {
         throw new \RuntimeException('Could not parse "' . $this->confFilePath . '"');
     }
 }