setName('domain:add') ->setDescription('Add a domain') ->addOption('name', null, InputOption::VALUE_REQUIRED, 'Domain name') ->addOption('type', null, InputOption::VALUE_REQUIRED, 'Domain type') ->addOption('master', null, InputOption::VALUE_REQUIRED, 'Domain master') ->setHelp("%command.name% --master This describes the master nameserver from which this domain should be slaved. Takes IPs, not hostnames! USe \"null\" to set NULL value --type Posible values are: NATIVE, MASTER, SLAVE, SUPERSLAVE Recommaned value: NATIVE For reference to the generated querys check: MASTER-SLAVE-QUERIES https://doc.powerdns.com/md/authoritative/backend-generic-mypgsql/#MASTER-SLAVE-QUERIES Use \"null\" to set NULL value."); } protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $name = $this->getInput()->getOption('name'); $master = $this->getInput()->getOption('master'); $type = $this->getInput()->getOption('type'); while (null === $name || trim($name) === '') { $name = $this->getHelper('dialog')->ask($this->getOutput(), 'Name: ', null); } if ($master === 'null') { $master = null; } elseif (null === $master || trim($master) === '') { $response = $this->getHelper('dialog')->ask($this->getOutput(), 'MASTER [null]: ', null); $master = empty($response) ? null : $response; } if ($type === 'null') { $type = null; } elseif (null === $type) { $response = $this->getHelper('dialog')->ask($this->getOutput(), 'Type [NATIVE]: ', null); $type = empty($response) ? 'NATIVE' : $response; } if (!$this->getHelper('validator')->isDomainMaster($master)) { $this->getOutput()->writeln('Invalid master.'); return; } if (!$this->getHelper('validator')->isDomainName($name)) { $this->getOutput()->writeln('Invalid name.'); return; } if (!$this->getHelper('validator')->isDomainType($type)) { $this->getOutput()->writeln('Invalid type.'); return; } if (DomainQuery::create()->findOneByName($name)) { $this->getOutput()->writeln('The domain already exists.'); return; } $domain = (new Domain()) ->setName($name) ->setMaster($master) ->setType($type); $domain->save(); $this->getOutput()->writeln('Domain added.'); } }