예제 #1
0
파일: hc.php 프로젝트: niieani/napkin
use HypoConf\Paths;
use PEAR2\Console\CommandLine;
//use PEAR2\Console\Color;
set_error_handler('\\Tools\\Errors::Handle');
Paths::$root = __DIR__;
Paths::$db = __DIR__ . '/database';
// create the parser
$parser = new CommandLine(array('name' => 'HypoConf', 'description' => 'A configuration manager for nginx, PHP with PHP-FPM and MySQL with a command line interface', 'version' => '0.4 alpha', 'add_help_option' => FALSE, 'add_version_option' => TRUE));
// add a global option to make the program verbose
$parser->addOption('verbose', array('short_name' => '-v', 'long_name' => '--verbose', 'action' => 'StoreInt', 'default' => 1, 'description' => 'set verbose level output (-1 quiet, 5 debug level)'));
$parser->addOption('stdout', array('short_name' => '-s', 'long_name' => '--stdout', 'action' => 'StoreTrue', 'default' => false, 'description' => 'turn on output to console instead of writing files'));
$parser->addOption('debug', array('short_name' => '-d', 'long_name' => '--debug', 'action' => 'StoreTrue', 'default' => false, 'description' => 'turn on debugging'));
$parser->addOption('force', array('short_name' => '-f', 'long_name' => '--force', 'action' => 'StoreTrue', 'default' => false, 'description' => 'force a specific action without asking for confirmation'));
$cmd = array();
// add the foo subcommand
$cmd['enable'] = $parser->addCommand('enable', array('description' => 'Enables a site', 'aliases' => array('en', 'e')));
$cmd['enable']->addArgument('enable', array());
// add the bar subcommand
$cmd['disable'] = $parser->addCommand('disable', array('description' => 'Disables a site', 'aliases' => array('dis', 'd')));
$cmd['disable']->addArgument('disable', array());
$cmd['disable']->addOption('placeholder', array('short_name' => '-p', 'long_name' => '--placeholder', 'help_name' => '/home/overquota.html'));
// add the set subcommand
$cmd['set'] = $parser->addCommand('set', array('description' => 'Sets the parameter of a website, user or template to specified value(s).', 'aliases' => array('s', 'setting')));
$cmd['set']->addArgument('name', array('description' => 'site, user (when prefixed with @) or template (when prefixed with +)'));
$cmd['set']->addArgument('chain', array('description' => 'configuration chain (eg. nginx.php)'));
$cmd['set']->addArgument('values', array('description' => 'value(s) to set', 'multiple' => true));
// add the setlist subcommand
$cmd['setlist'] = $parser->addCommand('setlist', array('description' => 'Shows the list of all available settings.', 'aliases' => array('sl', 'settings')));
$cmd['setlist']->addArgument('name', array('description' => '', 'optional' => true));
$cmd['help'] = $parser->addCommand('help', array('description' => 'shows general help or if help [argument] specified displays more about a certain function', 'aliases' => array('h')));
$cmd['help']->addArgument('setting', array('description' => 'displays detailed help for the specified setting', 'optional' => true));