initial attempt at trying to return an exit value within the cli

pull/298/head
David Goodwin 5 years ago
parent 284d4b2eb0
commit 9cd7dac187

@ -11,11 +11,11 @@ class CliDelete extends Shell {
*/ */
public function execute() { public function execute() {
if (empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); return $this->__interactive();
} }
if (!empty($this->args[0])) { if (!empty($this->args[0])) {
$this->__handle($this->args[0]); return $this->__handle($this->args[0]);
} }
} }
@ -33,7 +33,7 @@ class CliDelete extends Shell {
$create = $this->in($question, array('y','n')); $create = $this->in($question, array('y','n'));
if ($create == 'y') { if ($create == 'y') {
$this->__handle($address); return $this->__handle($address);
} }
} }
@ -47,14 +47,15 @@ class CliDelete extends Shell {
if (!$handler->init($address)) { if (!$handler->init($address)) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
return; return 1;
} }
if (!$handler->delete()) { if (!$handler->delete()) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
} else { return 1;
$this->out($handler->infomsg); }
} $this->out($handler->infomsg);
return 0;
} }
/** /**
@ -80,7 +81,7 @@ class CliDelete extends Shell {
Deletes $module <address> in non-interactive mode. Deletes $module <address> in non-interactive mode.
" "
); );
$this->_stop(); $this->_stop(1);
} }
} }

@ -16,9 +16,9 @@ class CliEdit extends Shell {
*/ */
public function execute() { public function execute() {
if (empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); return $this->__interactive();
} else { } else {
$this->__handle_params(); return $this->__handle_params();
} }
} }
@ -58,14 +58,11 @@ class CliEdit extends Shell {
} else { # not editable, unknown field etc. } else { # not editable, unknown field etc.
$param_error = 1; $param_error = 1;
$this->err("invalid parameter --$key => $val"); $this->err("invalid parameter --$key => $val");
return 1;
} }
} }
if ($param_error) { return $this->__handle($this->args[0], $values);
$this->_stop(1);
}
$this->__handle($this->args[0], $values);
} }
/** /**
@ -103,7 +100,7 @@ class CliEdit extends Shell {
foreach ($form_fields as $key => $field) { foreach ($form_fields as $key => $field) {
if ($field['editable'] && $field['display_in_form'] && $key != $id_field) { if ($field['editable'] && $field['display_in_form'] && $key != $id_field) {
while (0 == 0) { # endlees loop - except if input is valid while (true) { # endlees loop - except if input is valid
$question = $field['label'] . ':'; $question = $field['label'] . ':';
if ($field['desc'] != '') { if ($field['desc'] != '') {
$question .= "\n(" . $field['desc'] . ')'; $question .= "\n(" . $field['desc'] . ')';
@ -147,7 +144,8 @@ class CliEdit extends Shell {
} }
if (is_null($values[$key])) { # TODO: insull() is probably obsoleted by change in Shell class if (is_null($values[$key])) { # TODO: insull() is probably obsoleted by change in Shell class
echo "*** value of $key is NULL - this should not happen! ***"; $this->err("*** value of $key is NULL - this should not happen! ***");
return 1;
} }
if ($values[$key] == '' && (!$this->new)) { # edit mode if ($values[$key] == '' && (!$this->new)) { # edit mode
@ -162,6 +160,7 @@ class CliEdit extends Shell {
if (isset($handler->errormsg[$key])) { # only check the errormessage for this field if (isset($handler->errormsg[$key])) { # only check the errormessage for this field
$this->err($handler->errormsg[$key]); $this->err($handler->errormsg[$key]);
return 1;
} else { } else {
break; break;
} }
@ -169,7 +168,7 @@ class CliEdit extends Shell {
} # end if $field[editable] etc. } # end if $field[editable] etc.
} # end foreach } # end foreach
$this->__handle($values[$id_field], $values); return $this->__handle($values[$id_field], $values);
} }
/** /**
@ -179,22 +178,23 @@ class CliEdit extends Shell {
$handler = new $this->handler_to_use($this->new); $handler = new $this->handler_to_use($this->new);
if (!$handler->init($id)) { if (!$handler->init($id)) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
return; return 1;
} }
if (!$handler->set($values)) { if (!$handler->set($values)) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
return; return 1;
} }
if (!$handler->store()) { if (!$handler->store()) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
} else { return 1;
$this->out(""); }
$this->out($handler->infomsg);
$this->hr(); $this->out("");
} $this->out($handler->infomsg);
return; $this->hr();
return 0;
} }
/** /**
@ -247,7 +247,7 @@ class CliEdit extends Shell {
} }
$this->_stop(); $this->_stop(1);
} }
} }
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */

@ -75,7 +75,7 @@ class CliScheme extends Shell {
$this->hr(); $this->hr();
$this->out('Note that the above is only a template.'); $this->out('Note that the above is only a template.');
$this->out('You might need to adjust some parts.'); $this->out('You might need to adjust some parts.');
return; return 0;
} }
/** /**
@ -96,7 +96,7 @@ class CliScheme extends Shell {
" "
); );
$this->_stop(); $this->_stop(1);
} }
} }
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */

@ -11,11 +11,11 @@ class CliView extends Shell {
*/ */
public function execute() { public function execute() {
if (empty($this->args)) { if (empty($this->args)) {
$this->__interactive(); return $this->__interactive();
} }
if (!empty($this->args[0])) { if (!empty($this->args[0])) {
$this->__handle($this->args[0]); return $this->__handle($this->args[0]);
} }
} }
@ -29,7 +29,7 @@ class CliView extends Shell {
$question = "Which $module do you want to view?"; $question = "Which $module do you want to view?";
$address = $this->in($question); $address = $this->in($question);
$this->__handle($address); return $this->__handle($address);
} }
/** /**
@ -42,12 +42,12 @@ class CliView extends Shell {
if (!$handler->init($address)) { if (!$handler->init($address)) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
return; return 1;
} }
if (!$handler->view()) { if (!$handler->view()) {
$this->err($handler->errormsg); $this->err($handler->errormsg);
return; return 1;
} }
$result = $handler->result(); $result = $handler->result();

@ -33,4 +33,4 @@ LIB="${self/%postfixadmin-cli/}"
exec php -q "${LIB}postfixadmin-cli.php" "$@" exec php -q "${LIB}postfixadmin-cli.php" "$@"
exit; exit $?

@ -153,7 +153,7 @@ class PostfixAdmin {
if (!isset($this->args[0])) { if (!isset($this->args[0])) {
$this->help(); $this->help();
return; return 1;
} }
$this->shell = $this->args[0]; $this->shell = $this->args[0];
@ -164,7 +164,7 @@ class PostfixAdmin {
if ($this->shell == 'help') { if ($this->shell == 'help') {
$this->help(); $this->help();
return; return 1;
} }
$command = 'help'; # not the worst default ;-) $command = 'help'; # not the worst default ;-)
@ -181,7 +181,7 @@ class PostfixAdmin {
if (!class_exists($this->shellClass)) { if (!class_exists($this->shellClass)) {
$this->stderr('Unknown task ' . $this->shellCommand); $this->stderr('Unknown task ' . $this->shellCommand);
return; return 1;
} }
$shell = new $this->shellClass($this); $shell = new $this->shellClass($this);
@ -190,7 +190,7 @@ class PostfixAdmin {
if (!class_exists($shell->handler_to_use)) { if (!class_exists($shell->handler_to_use)) {
$this->stderr('Unknown module ' . $this->shell); $this->stderr('Unknown module ' . $this->shell);
return; return 1;
} }
$task = ucfirst($command); $task = ucfirst($command);
@ -211,14 +211,14 @@ class PostfixAdmin {
if (isset($this->args[0]) && $this->args[0] == 'help') { if (isset($this->args[0]) && $this->args[0] == 'help') {
if (method_exists($shell, 'help')) { if (method_exists($shell, 'help')) {
$shell->help(); $shell->help();
exit(); return 1;
} else { } else {
$this->help(); $this->help();
return 1;
} }
} }
$shell->execute(); return $shell->execute();
return;
} }
} }
@ -244,13 +244,14 @@ class PostfixAdmin {
if ($missingCommand && method_exists($shell, 'main')) { if ($missingCommand && method_exists($shell, 'main')) {
$shell->startup(); $shell->startup();
$shell->main(); return $shell->main();
} elseif (!$privateMethod && method_exists($shell, $command)) { } elseif (!$privateMethod && method_exists($shell, $command)) {
$this->shiftArgs(); $this->shiftArgs();
$shell->startup(); $shell->startup();
$shell->{$command}(); return $shell->{$command}();
} else { } else {
$this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'postfixadmin-cli {$this->shell} help'.\n\n"); $this->stderr("Unknown {$this->shellName} command '$command'.\nFor usage, try 'postfixadmin-cli {$this->shell} help'.\n\n");
return 1;
} }
} }
@ -406,6 +407,8 @@ define("POSTFIXADMIN_CLI", 1);
require_once(dirname(__FILE__) . '/../common.php'); require_once(dirname(__FILE__) . '/../common.php');
$dispatcher = new PostfixAdmin($argv); $dispatcher = new PostfixAdmin($argv);
$dispatcher->dispatch(); $retval = $dispatcher->dispatch();
exit($retval);
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */

Loading…
Cancel
Save