diff --git a/setup/inc/class.setup_cmd_database.inc.php b/setup/inc/class.setup_cmd_database.inc.php index 07c6a6ef15..b78fc08473 100644 --- a/setup/inc/class.setup_cmd_database.inc.php +++ b/setup/inc/class.setup_cmd_database.inc.php @@ -15,6 +15,11 @@ */ class setup_cmd_database extends setup_cmd { + /** + * Allow to run this command via setup-cli + */ + const SETUP_CLI_CALLABLE = true; + /** * Instance of egw_db to connect or create the db * diff --git a/setup/inc/class.setup_cmd_ldap.inc.php b/setup/inc/class.setup_cmd_ldap.inc.php index f61d3dfe6a..4fa40f34b7 100644 --- a/setup/inc/class.setup_cmd_ldap.inc.php +++ b/setup/inc/class.setup_cmd_ldap.inc.php @@ -15,6 +15,11 @@ */ class setup_cmd_ldap extends setup_cmd { + /** + * Allow to run this command via setup-cli + */ + const SETUP_CLI_CALLABLE = true; + /** * Instance of ldap object * diff --git a/setup/inc/class.setup_cmd_showheader.inc.php b/setup/inc/class.setup_cmd_showheader.inc.php index 479b201573..ac00cc1686 100644 --- a/setup/inc/class.setup_cmd_showheader.inc.php +++ b/setup/inc/class.setup_cmd_showheader.inc.php @@ -18,6 +18,11 @@ */ class setup_cmd_showheader extends setup_cmd { + /** + * Allow to run this command via setup-cli + */ + const SETUP_CLI_CALLABLE = true; + /** * Constructor * diff --git a/setup/setup-cli.php b/setup/setup-cli.php index 9f7577dda4..4227bde720 100755 --- a/setup/setup-cli.php +++ b/setup/setup-cli.php @@ -42,9 +42,19 @@ include('inc/functions.inc.php'); $GLOBALS['egw_setup']->translation->no_translation_marker = ''; $GLOBALS['egw_setup']->system_charset = $charset; +/** + * Echo the exception message and exit the script with a numeric code, does NOT return + * + * @param Exception $e + */ function cli_exception_handler(Exception $e) { - fail($e->getCode(),$e->getMessage()); + echo $e->getMessage()."\n"; +// if ($e instanceof egw_exception_assertion_failed && !($e instanceof egw_exception_wrong_userinput)) + { + echo $e->getTraceAsString()."\n"; + } + exit($e->getCode() ? $e->getCode() : 9999); // always give a non-zero exist status } set_exception_handler('cli_exception_handler'); @@ -109,7 +119,27 @@ switch($action) break; default: - fail(90,lang("Unknown option '%1' !!!",$action)); + // we allow to call admin_cmd classes directly, if they define the constant SETUP_CLI_CALLABLE + if (substr($action,0,2) == '--' && class_exists($class = str_replace('-','_',substr($action,2))) && + is_subclass_of($class,'admin_cmd') && constant($class.'::SETUP_CLI_CALLABLE')) + { + $args = null; + foreach($arguments as $arg) + { + list($name,$value) = explode('=',$arg,2); + if(property_exists('admin_cmd',$name)) // dont allow to overwrite admin_cmd properties + { + throw new egw_exception_wrong_userinput(lang("Invalid argument '%1' !!!",$arg),90); + } + $args[$name] = $value; + } + $cmd = new $class($args); + $msg = $cmd->run(); + if (is_array($msg)) $msg = print_r($msg,true); + echo "$msg\n"; + break; + } + throw new egw_exception_wrong_userinput(lang("Unknown option '%1' !!!",$action),90); } exit(0); @@ -402,14 +432,7 @@ function do_header($create,&$arguments) array_unshift($arguments,$create ? '--create-header' : '--edit-header'); $cmd = new setup_cmd_header($create?'create':'edit',$arguments); - try { - $msg = $cmd->run(); - } - catch(Exception $e) { - fail($e->getCode(),$e->getMessage()); - } - echo "\n$msg\n\n"; - exit(0); + echo $cmd->run()."\n"; } /**