/** * Constructs the Graph */ public function __construct() { $this->graph = new \Fhaculty\Graph\Graph(); $this->graphviz = new GraphViz(); $this->getopt = new Getopt(array(new Option(null, 'extpath', Getopt::REQUIRED_ARGUMENT), new Option(null, 'extpattern', Getopt::REQUIRED_ARGUMENT), new Option(null, 'versions'), new Option(null, 'version'))); $this->getopt->setBanner(implode(PHP_EOL, array("[0;32mGraph[0m version " . self::VERSION, "[0;31m%s[0m", "Usage: graph [options]")) . PHP_EOL); }
/** * The main logic block for dispatching the CLI to the implementation * classes. Assuming it makes it all the way to the actual method cleanly, * its return code will be propagated up. Otherwise, RuntimeExceptions exit * 1 (user error), LogicExceptions exit 2 (programmer error), and everything * else exits 3 (doom) * * @return int The intended exit status cide */ public function run() { $trie = self::getCommandTrie(); $class = Utilities::searchTrieFromArgv($trie, $this->argv); $cmd = new $class(); $banner = $cmd->getBanner(); try { $opt = new Getopt(); $opt->addOptions($cmd->getOptions()); $opt->addOptions(self::getDefaultOptions()); if ($banner) { $opt->setBanner($banner . PHP_EOL); } $opt->parse(implode(' ', $this->argv)); } catch (\UnexpectedValueException $e) { // Unexpected CLI arguments $this->console->exception($e); $this->console->writeLine($opt->getHelpText()); return 1; } catch (\InvalidArgumentException $e) { // Command is broken - most likely duplicated arguments $this->console->exception($e); return 2; } catch (\Exception $e) { // Catch-all, $this->console->exception($e); return 3; } // Unfortunately we can't easily do this earlier. Native getopt() is // useless on all subcommands, and the class implementation screams // about unexpected values. $v = Utilities::parseVerbosity($opt['q'], $opt['v']); $this->console->setVerbosity($v); if ($opt['help']) { return $this->showHelp($cmd, $opt->getHelpText()); } if ($opt['version']) { return $this->showVersion($cmd); } try { return $cmd->setOutput($this->console)->setOperands($opt->getOperands())->setOptionValues($opt->getOptions())->execute(); } catch (\RuntimeException $e) { $this->console->exception($e); $this->console->writeLine($opt->getHelpText()); return 1; } catch (\LogicException $e) { $this->console->exception($e); return 2; } catch (\Exception $e) { $this->console->exception($e); return 3; } }
* @TODO * - add comite to recipients ? */ require_once 'core.php'; echo "Génération des listes de classe\n\n"; // ---------------------------------------------------------------------------- // Initialization // define('GETOPT_HELP_WIDTH', 21); // Process command-line arguments use Ulrichsg\Getopt\Getopt; use Ulrichsg\Getopt\Option; use Ulrichsg\Getopt\Argument; $padding = str_repeat(' ', GETOPT_HELP_WIDTH + 1); $opt = new Getopt(array((new Option('f', 'filter', Getopt::REQUIRED_ARGUMENT))->setDescription('Ne traiter que les classes contenant <arg>'), (new Option('t', 'type', Getopt::REQUIRED_ARGUMENT))->setDescription("Type de fichier à générer: x=Excel, p=PDF (défaut), t=les deux")->setArgument(new Argument('p', 'ExportFileFormat::validate', 'type')), (new Option('s', 'send'))->setDescription("Envoi des fichiers Excel générés par e-mail\n" . $padding . "dédoubler l'argument (-ss) pour forcer l'envoi"), (new Option('k', 'keep'))->setDescription('Conserver les fichiers après envoi par e-mail'), (new Option('d', 'debug'))->setDescription("Utiliser une adresse de debug au lieu des destinataires\n" . $padding . "réels (implique l'option -s)"), (new Option('h', 'help'))->setDescription("Afficher ce message d'aide"))); $opt->setBanner("Utilisation: %s [options]\n"); try { $opt->parse(); } catch (UnexpectedValueException $e) { echo $opt->getHelpText(GETOPT_HELP_WIDTH) . "\n"; exit_error('Paramètre invalide (' . $e->getMessage() . ')'); } if ($opt['help']) { echo $opt->getHelpText(GETOPT_HELP_WIDTH); exit(0); } if ($opt['debug']) { echo 'DEBUG MODE: envoi des messages sur ' . implode(', ', $mail_debug_addresses) . "\n"; } // Retrieve data from classes export view if ($opt['filter']) {