diff --git a/setup/cli/manage.php b/setup/cli/manage.php index c738318291c9fb861bad7139f7fd75403da6d876..e11bfafeb3378a550993338117dc94cfcaf10d29 100755 --- a/setup/cli/manage.php +++ b/setup/cli/manage.php @@ -20,12 +20,12 @@ class Manager extends Module { include_once $script; global $registered_modules; - $this->epilog = + $this->epilog = "Currently available modules follow. Use 'manage.php <module> --help' for usage regarding each respective module:"; parent::showHelp(); - + echo "\n"; foreach ($registered_modules as $name=>$mod) echo str_pad($name, 20) . $mod->prologue . "\n"; @@ -43,9 +43,10 @@ class Manager extends Module { if ($val == $action) unset($argv[$idx]); - include_once dirname(__file__) . '/modules/' . $action . '.php'; + foreach (glob(dirname(__file__).'/modules/*.php') as $script) + include_once $script; $module = Module::getInstance($action); - $module->run(); + $module->_run(); } } } diff --git a/setup/cli/modules/class.module.php b/setup/cli/modules/class.module.php index de30f16321457bec2bb0c8762ed790d583e3ca6e..501e6534e78a71be08b62422d2f383f9d215b585 100644 --- a/setup/cli/modules/class.module.php +++ b/setup/cli/modules/class.module.php @@ -1,7 +1,7 @@ <?php class Option { - + var $default = false; function Option() { @@ -23,6 +23,8 @@ class Option { : null; $this->metavar = (isset($options['metavar'])) ? $options['metavar'] : 'var'; + $this->nargs = (isset($options['nargs'])) ? $options['nargs'] + : 1; } function hasArg() { @@ -87,6 +89,9 @@ class Module { var $usage = '$script [options] $args [arguments]'; var $autohelp = true; + var $_options; + var $_args; + function Module() { call_user_func_array(array($this, '__construct'), func_get_args()); } @@ -143,9 +148,8 @@ class Module { function getArgument($name, $default=false) { $this->parseOptions(); - foreach (array_keys($this->arguments) as $idx=>$arg) - if ($arg == $name && isset($this->_args[$idx])) - return $this->_args[$idx]; + if (isset($this->_args[$name])) + return $this->_args[$name]; return $default; } @@ -160,6 +164,8 @@ class Module { foreach (array_keys($this->arguments) as $idx=>$name) if (!isset($this->_args[$idx])) $this->optionError($name . " is a required argument"); + else + $this->_args[$name] = &$this->_args[$idx]; if ($this->autohelp && $this->getOption('help')) { $this->showHelp(); @@ -173,7 +179,12 @@ class Module { die(); } - /* abstract */ function run() { + function _run() { + $this->parseOptions(); + return $this->run($this->_args, $this->_options); + } + + /* abstract */ function run($args, $options) { } /* static */ function register($action, $class) { diff --git a/setup/cli/modules/unpack.php b/setup/cli/modules/unpack.php index 58fc70e4f781b6199829b35ba39c2a5dfa3e6d9b..fca8f0ac2405686d72c624786ccefa6a1cac4ebd 100644 --- a/setup/cli/modules/unpack.php +++ b/setup/cli/modules/unpack.php @@ -114,7 +114,7 @@ class Unpacker extends Module { return INCLUDE_DIR; } - function run() { + function run($args, $options) { $this->destination = $this->getArgument('install-path'); if (!is_dir($this->destination)) if (!mkdir($this->destination, 0751, true))