setName('interface:create') ->setDescription('Create a new interface for the phpMAE.') ->addArgument('coid', InputArgument::REQUIRED, 'The COID of the object.') ->addOption('force', 'f', InputOption::VALUE_OPTIONAL, 'Forces new object creation and replaces existing files.', false) ->addOption('confjob', null, InputOption::VALUE_OPTIONAL, 'Calls "cloudobjects" to create a configuration job for the new interface.', false); } protected function execute(InputInterface $input, OutputInterface $output): int { if (!CredentialManager::isConfigured()) throw new \Exception("The 'cloudobjects' CLI tool must be installed and authorized."); $coid = COIDParser::fromString($input->getArgument('coid')); if (COIDParser::getType($coid)!=COIDParser::COID_VERSIONED && COIDParser::getType($coid)!=COIDParser::COID_UNVERSIONED) throw new \Exception("Invalid COID: ".(string)$coid); $name = COIDParser::getName($coid); $version = COIDParser::getVersion($coid); $fullName = isset($version) ? $name.".".$version : $name; if (!file_exists($fullName.'.xml') || $input->getOption('force') !== false) { // Create RDF configuration file $content = "\n" . "\n" . "\n" . " \n" . " \n" . " \n" . ""; file_put_contents($fullName.'.xml', $content); $output->writeln("Written ".$fullName.".xml."); } else { // RDF configuration file already exists $output->writeln($fullName.".xml already exists."); } if (!file_exists($fullName.'.php') || $input->getOption('force') !== false) { // Create PHP source file $content = "writeln("Written ".$fullName.".php."); } else { $output->writeln($fullName.".php already exists."); } if ($input->getOption('confjob') !== false) { $output->writeln("Calling cloudobjects ..."); passthru("cloudobjects configuration-job:create ".$fullName.".xml"); } return Command::SUCCESS; } }