addOption("init", null, InputOption::VALUE_NONE, "Initialize a new devmode.json file"); } protected function execute(InputInterface $input, OutputInterface $output) { $env = $this->getEnvironment(); if ($input->getOption("init")) { $conffile = $env->getConfigDirectory()."/devmode.json"; if (file_exists($conffile)) { $output->writeln("You have already created a devmode.json file"); return Command::FAILURE; } $this->initConfig($conffile, $input, $output); return Command::SUCCESS; } $devmode = new DevMode($env); $devmode->run(); return Command::SUCCESS; } private function initConfig(string $file, InputInterface $input, OutputInterface $output) { $qh = new QuestionHelper(); $titleQuestion = new Question("Window title []: ", null); $title = $qh->ask($input, $output, $titleQuestion); $commandQuestion = new Question(" Command []: ", null); $startup = []; $output->writeln("Startup commands. Enter an empty line to continue."); while ($command = $qh->ask($input, $output, $commandQuestion)) { $startup[] = $command; } $shutdown = []; $output->writeln("Shutdown commands. Enter an empty line to continue."); while ($command = $qh->ask($input, $output, $commandQuestion)) { $shutdown[] = $command; } $json = [ 'devmode' => [ ] ]; if ($title) $json['devmode']['title'] = $title; $json['devmode']['startup'] = $startup; $json['devmode']['shutdown'] = $shutdown; $out = json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); file_put_contents($file, $out); } }