declare option as argument when value is required and no default option can be provided

This commit is contained in:
Nicolas Le Goff
2012-05-04 16:12:10 +02:00
parent 70f5f2b93c
commit be63d495be
3 changed files with 51 additions and 39 deletions

View File

@@ -31,9 +31,13 @@ class module_console_fieldsDelete extends Command
$this->setDescription('Delete a documentation field from a Databox'); $this->setDescription('Delete a documentation field from a Databox');
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id'); // $this->addArgument('name', InputArgument::REQUIRED, 'Metadata structure ids for source');
$this->addArgument('meta_struct_id', InputArgument::REQUIRED, 'Metadata structure id destination');
$this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id');
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id'); // $this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
//
// $this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
return $this; return $this;
} }
@@ -41,14 +45,14 @@ class module_console_fieldsDelete extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $input->getOption('sbas_id')) if ( ! $input->getArgument('sbas_id'))
throw new \Exception('Missing argument sbas_id'); throw new \Exception('Missing argument sbas_id');
if ( ! $input->getOption('meta_struct_id')) if ( ! $input->getArgument('meta_struct_id'))
throw new \Exception('Missing argument meta_struct_id'); throw new \Exception('Missing argument meta_struct_id');
try { try {
$databox = \databox::get_instance((int) $input->getOption('sbas_id')); $databox = \databox::get_instance((int) $input->getArgument('sbas_id'));
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln("<error>Invalid databox id </error>"); $output->writeln("<error>Invalid databox id </error>");
@@ -56,7 +60,7 @@ class module_console_fieldsDelete extends Command
} }
try { try {
$field = $databox->get_meta_structure()->get_element((int) $input->getOption('meta_struct_id')); $field = $databox->get_meta_structure()->get_element((int) $input->getArgument('meta_struct_id'));
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln("<error>Invalid meta struct id </error>"); $output->writeln("<error>Invalid meta struct id </error>");

View File

@@ -31,27 +31,31 @@ class module_console_fieldsMerge extends Command
$this->setDescription('Merge databox structure fields'); $this->setDescription('Merge databox structure fields');
$this->addOption( $this->addArgument('source', InputArgument::REQUIRED, 'Metadata structure ids for source');
'source' $this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id');
, 'f' $this->addArgument('destination', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Metadata structure id destination');
, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
, 'Metadata structure ids for source'
, array()
);
$this->addOption( // $this->addOption(
'destination' // 'source'
, 'd' // , 'f'
, InputOption::VALUE_REQUIRED // , InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY
, 'Metadata structure id destination' // , 'Metadata structure ids for source'
); // , array()
// );
$this->addOption( // $this->addOption(
'sbas_id' // 'destination'
, 's' // , 'd'
, InputOption::VALUE_REQUIRED // , InputOption::VALUE_REQUIRED
, 'Databox sbas_id' // , 'Metadata structure id destination'
); // );
// $this->addOption(
// 'sbas_id'
// , 's'
// , InputOption::VALUE_REQUIRED
// , 'Databox sbas_id'
// );
$this->addOption( $this->addOption(
'separator' 'separator'
@@ -68,11 +72,11 @@ class module_console_fieldsMerge extends Command
{ {
$output->writeln(""); $output->writeln("");
if ( ! $input->getOption('sbas_id')) if ( ! $input->getArgument('sbas_id'))
throw new \Exception('Missing argument sbas_id'); throw new \Exception('Missing argument sbas_id');
try { try {
$databox = \databox::get_instance((int) $input->getOption('sbas_id')); $databox = \databox::get_instance((int) $input->getArgument('sbas_id'));
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln("<error>Invalid databox id </error>"); $output->writeln("<error>Invalid databox id </error>");
@@ -81,19 +85,19 @@ class module_console_fieldsMerge extends Command
$sources = array(); $sources = array();
foreach ($input->getOption('source') as $source_id) { foreach ($input->getArgument('source') as $source_id) {
$sources[] = $databox->get_meta_structure()->get_element($source_id); $sources[] = $databox->get_meta_structure()->get_element($source_id);
} }
if (count($sources) === 0) if (count($sources) === 0)
throw new \Exception('No sources to proceed'); throw new \Exception('No sources to proceed');
if ( ! $input->getOption('destination')) if ( ! $input->getArgument('destination'))
throw new \Exception('Missing argument destination'); throw new \Exception('Missing argument destination');
$separator = ' ' . $input->getOption('separator') . ' '; $separator = ' ' . $input->getOption('separator') . ' ';
$destination = $databox->get_meta_structure()->get_element($input->getOption('destination')); $destination = $databox->get_meta_structure()->get_element($input->getArgument('destination'));
$types = $multis = array(); $types = $multis = array();

View File

@@ -31,11 +31,15 @@ class module_console_fieldsRename extends Command
$this->setDescription('Rename a documentation field from a Databox'); $this->setDescription('Rename a documentation field from a Databox');
$this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id'); $this->addArgument('name', InputArgument::REQUIRED, 'Metadata structure ids for source');
$this->addArgument('meta_struct_id', InputArgument::REQUIRED, 'Metadata structure id destination');
$this->addArgument('sbas_id', InputArgument::REQUIRED, 'Databox sbas_id');
$this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id'); // $this->addOption('sbas_id', 's', InputOption::VALUE_REQUIRED, 'Databox sbas_id');
//
$this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'The new name'); // $this->addOption('meta_struct_id', 'm', InputOption::VALUE_REQUIRED, 'Databox meta structure Id');
//
// $this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'The new name');
return $this; return $this;
} }
@@ -43,19 +47,19 @@ class module_console_fieldsRename extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $input->getOption('sbas_id')) if ( ! $input->getArgument('sbas_id'))
throw new \Exception('Missing argument sbas_id'); throw new \Exception('Missing argument sbas_id');
if ( ! $input->getOption('meta_struct_id')) if ( ! $input->getArgument('meta_struct_id'))
throw new \Exception('Missing argument meta_struct_id'); throw new \Exception('Missing argument meta_struct_id');
if ( ! $input->getOption('name')) if ( ! $input->getArgument('name'))
throw new \Exception('Missing argument name'); throw new \Exception('Missing argument name');
$new_name = $input->getOption('name'); $new_name = $input->getArgument('name');
try { try {
$databox = \databox::get_instance((int) $input->getOption('sbas_id')); $databox = \databox::get_instance((int) $input->getArgument('sbas_id'));
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln("<error>Invalid databox id </error>"); $output->writeln("<error>Invalid databox id </error>");