diff --git a/setup/cli/manage.php b/setup/cli/manage.php index 080fb3cf4bd9570e08882420c977a1d6d50d9319..bfd59f9f0fe2e1b85fcf3cbbbac90744ea4b2290 100755 --- a/setup/cli/manage.php +++ b/setup/cli/manage.php @@ -3,6 +3,9 @@ require_once "modules/class.module.php"; +if (!function_exists('noop')) { function noop() {} } +session_set_save_handler('noop','noop','noop','noop','noop','noop'); + class Manager extends Module { var $prologue = "Manage one or more osTicket installations"; @@ -13,7 +16,7 @@ class Manager extends Module { var $usage = '$script action [options] [arguments]'; - var $autohelp = true; + var $autohelp = false; function showHelp() { foreach (glob(dirname(__file__).'/modules/*.php') as $script) @@ -31,12 +34,12 @@ class Manager extends Module { echo str_pad($name, 20) . $mod->prologue . "\n"; } - function run() { - if ($this->getOption('help') && !$this->getArgument('action')) + function run($args, $options) { + if ($options['help'] && !$args['action']) $this->showHelp(); else { - $action = $this->getArgument('action'); + $action = $args['action']; global $argv; foreach ($argv as $idx=>$val) @@ -45,8 +48,11 @@ class Manager extends Module { foreach (glob(dirname(__file__).'/modules/*.php') as $script) include_once $script; - $module = Module::getInstance($action); - $module->_run(); + if (($module = Module::getInstance($action))) + return $module->_run($args['action']); + + $this->stderr->write("Unknown action given\n"); + $this->showHelp(); } } } @@ -56,6 +62,6 @@ if (php_sapi_name() != "cli") $manager = new Manager(); $manager->parseOptions(); -$manager->run(); +$manager->_run(basename(__file__)); ?> diff --git a/setup/cli/modules/class.module.php b/setup/cli/modules/class.module.php index 142a00283a23c1896a0ad64d2b83de499fc55b66..437f87c609eb6b63f6799978ce324f437a456ca5 100644 --- a/setup/cli/modules/class.module.php +++ b/setup/cli/modules/class.module.php @@ -39,6 +39,8 @@ class Option { $value = null; elseif ($value) $nargs = 1; + if ($this->type == 'int') + $value = (int)$value; switch ($this->action) { case 'store_true': $value = true; @@ -49,10 +51,17 @@ class Option { case 'store_const': $value = $this->const; break; + case 'append': + if (!isset($destination[$this->dest])) + $destination[$this->dest] = array($value); + else { + $T = &$destination[$this->dest]; + $T[] = $value; + $value = $T; + } + break; case 'store': default: - if ($this->type == 'int') - $value = (int)$value; break; } $destination[$this->dest] = $value; @@ -71,7 +80,7 @@ class Option { else $switches = sprintf(" %s, %s", $short[0], $long[0]); $help = preg_replace('/\s+/', ' ', $this->help); - if (strlen($switches) > 24) + if (strlen($switches) > 23) $help = "\n" . str_repeat(" ", 24) . $help; else $switches = str_pad($switches, 24); @@ -103,6 +112,7 @@ class Module { var $epilog = ""; var $usage = '$script [options] $args [arguments]'; var $autohelp = true; + var $module_name; var $stdout; var $stderr; @@ -128,11 +138,13 @@ class Module { if ($this->prologue) echo $this->prologue . "\n\n"; - echo "Usage:\n"; global $argv; + $manager = @$argv[0]; + + echo "Usage:\n"; echo " " . str_replace( array('$script', '$args'), - array($argv[0], implode(' ', array_keys($this->arguments))), + array($manager ." ". $this->module_name, implode(' ', array_keys($this->arguments))), $this->usage) . "\n"; ksort($this->options); @@ -205,15 +217,18 @@ class Module { die(); } - function _run() { + function _run($module_name) { + $this->module_name = $module_name; $this->parseOptions(); return $this->run($this->_args, $this->_options); } - /* abstract */ function run($args, $options) { + /* abstract */ + function run($args, $options) { } - /* static */ function register($action, $class) { + /* static */ + function register($action, $class) { global $registered_modules; $registered_modules[$action] = new $class(); }