From 1e0225e2c28364fdeac701e7ca23527331e6a686 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 3 Mar 2013 01:23:50 +0000 Subject: [PATCH] model/CliEdit.php: - help(): generate help output based on $handler->struct It shows all available options/fields, but might need some finetuning to look better git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1441 a1433add-5e2c-0410-b055-b7f2511e0802 --- model/CliEdit.php | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/model/CliEdit.php b/model/CliEdit.php index 44eeb2fc..d39780c6 100644 --- a/model/CliEdit.php +++ b/model/CliEdit.php @@ -205,14 +205,47 @@ echo "*** value of $key is NULL - this should not happen! ***"; * Displays help contents */ public function help() { + $cmd = 'edit'; + if ($this->new) $cmd = 'add'; + + $module = preg_replace('/Handler$/', '', $this->handler_to_use); + $module = strtolower($module); + # TODO: generate from $struct - $this->hr(); - $this->out("Usage: postfixadmin-cli user add
[] [-g]"); - $this->hr(); - $this->out('Commands:'); - $this->out("\n\tadd\n\t\tAdds mailbox in interactive mode."); - $this->out("\n\tadd
[] [-g] \n\t\tAdds mailbox for
with password of if -g with rand pw. in MB."); - $this->out(""); +# $this->hr(); + $this->out( +"Usage: + + postfixadmin-cli $module $cmd + + Adds $module in interactive mode. + +- or - + + postfixadmin-cli $module $cmd
--option value --option2 value [...] + + Adds $module in non-interactive mode. + + Available options are: +"); + + $handler = new $this->handler_to_use($this->new); + + $form_fields = $handler->getStruct(); + $id_field = $handler->getId_field(); + + foreach($form_fields as $key => $field) { + if ($field['editable'] && $field['display_in_form'] && $key != $id_field) { + $optkey = str_replace('_', '-', $key); + $this->out(" --$optkey"); + $this->out(" " . $field['label']); + if ($field['desc']) $this->out(" " . $field['desc']); + $this->out(""); + } + } + + + $this->_stop(); }