Skip to content
Snippets Groups Projects
Commit e30390b7 authored by Jared Hancock's avatar Jared Hancock
Browse files

Merge pull request #580 from greezybacon/revisit/cli


Address issues from the cli framework

Reviewed-By: default avatarJared Hancock <jared@osticket.com>
parents 501a7255 92690474
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
}
......
<?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());
}
......@@ -137,15 +142,16 @@ class Module {
$this->parseOptions();
if (isset($this->_options[$name]))
return $this->_options[$name];
elseif ($this->options[$name]->default)
return $this->options[$name]->default;
else
return $default;
}
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 +166,12 @@ 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];
foreach ($this->options as $name=>$opt)
if (!isset($this->_options[$name]))
$this->_options[$name] = $opt->default;
if ($this->autohelp && $this->getOption('help')) {
$this->showHelp();
......@@ -173,7 +185,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) {
......
......@@ -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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment