protected function parseOptions() { $argf = new ARGF(); $argc =& $argf->argc(); $argv =& $argf->argv(); $optparser = new Console_CommandLine(array('name' => basename($argv[0]), 'description' => 'A php migratory tool from 4 to 5 written in pure php', 'version' => '0.0.1')); $optparser->addOption('format', array('choices' => array('nodes', 'string', 'terminals', 'tokens', 'tree'), 'default' => 'string', 'description' => 'format of output (default: string)', 'long_name' => '--format', 'short_name' => '-f')); $optparser->addOption('in_place', array('action' => 'StoreTrue', 'description' => 'edit files in place', 'long_name' => '--in-place', 'short_name' => '-i')); $optparser->addOption('recursive', array('action' => 'StoreTrue', 'description' => 'migrate recursively', 'long_name' => '--recursive', 'short_name' => '-r')); $optparser->addOption('suffixes', array('default' => 'php,php4,php5,inc', 'description' => 'suffixes of files to be migrated (default: php,php4,php5,inc)', 'long_name' => '--suffixes', 'short_name' => '-s')); $optparser->addArgument('files', array('multiple' => true)); try { $result = $optparser->parse(); } catch (Exception $e) { $optparser->displayError($e->getMessage()); } $options =& $result->options; $args =& $result->args['files']; if ($options['recursive']) { if (count($args) < 2) { $optparser->displayError('target directory must be specified with -r'); } $target = $args[count($args) - 1]; if (!is_dir($target) && file_exists($target)) { $optparser->displayError('target directory cannot be a regular file'); } } $options['suffixes'] = split(',', $options['suffixes']); return array('options' => $options, 'args' => $args); }
protected function parseOptions() { $argf = new ARGF(); $argc =& $argf->argc(); $argv =& $argf->argv(); $optparser = new Console_CommandLine(array('name' => basename($argv[0]), 'description' => 'Find bugs in PHP5 Programs', 'version' => '0.0.1')); $optparser->addOption('format', array('long_name' => '--format', 'help_name' => 'FORMAT', 'choices' => array('nodes', 'string', 'terminals', 'tokens', 'tree'), 'default' => 'string', 'description' => 'format of output (default: string)')); $optparser->addOption('suffixes', array('long_name' => '--suffixes', 'help_name' => 'PATTERNS', 'default' => 'php,yml', 'description' => 'suffixes of files to be checked (default: php,yml)')); $optparser->addOption('priority', array('long_name' => '--priority', 'help_name' => 'LEVEL', 'choices' => array('low', 'middle', 'high'), 'default' => 'middle', 'description' => 'specify priority for bug reporting (default: middle)')); $optparser->addOption('recursive', array('action' => 'StoreTrue', 'description' => 'check recursively', 'long_name' => '--recursive', 'short_name' => '-r')); $optparser->addOption('debug', array('action' => 'StoreTrue', 'description' => 'turn on debug mode', 'long_name' => '--debug')); $optparser->addArgument('files', array('multiple' => true)); try { $result = $optparser->parse(); } catch (Exception $e) { $optparser->displayError($e->getMessage()); } $options =& $result->options; $args =& $result->args['files']; if ($options['recursive']) { if (count($args) < 2) { $optparser->displayError('target directory must be specified with -r'); } $target = $args[count($args) - 1]; if (!is_dir($target) && file_exists($target)) { $optparser->displayError('target directory cannot be a regular file'); } } $options['suffixes'] = split(',', $options['suffixes']); return array('options' => $options, 'args' => $args); }