Commit [r1575] Maximize Restore History

Quite big CLI cleanup (and more)

model/CliHelp.php:
- new class, used for "postfixadmin-cli $module help"
- replaces the PostfixAdmin* classes in scripts/shells/*.php

model/PFAHandler.php
- add public $taskNames with the list of supported CLI commands

scripts/postfixadmin-cli.php - dispatch():
- directly set the classes to load instead of using shell->loadTasks()
- when "postfixadmin-cli $module" is called, display help instead of
error message about "invalid command ''"
- make it more readable by moving error checks to the beginning
(replaces deeply nested if's with return statements)
- remove unused code parts

scripts/shells/*.php:
- remove PostfixAdmin* classes (obsoleted by CliHelp)
- remove $tasks (now in PFAHandler)
- delete alias.php and domain.php because nothing is left
- mailbox.php still contains PasswordTask

scripts/shells/shell.php:
- remove $taskNames (moved to PFAHandler)
- remove loadTasks() (integrated in postfixadmin-cli.php's dispatch())

christian_boltz 2013-11-13

removed /trunk/scripts/shells/domain.php
changed /trunk/model/PFAHandler.php
changed /trunk/scripts/postfixadmin-cli.php
changed /trunk/scripts/shells/mailbox.php
changed /trunk/scripts/shells/shell.php
copied /trunk/scripts/shells/alias.php -> /trunk/model/CliHelp.php
/trunk/model/PFAHandler.php Diff Switch to side-by-side view
Loading...
/trunk/scripts/postfixadmin-cli.php Diff Switch to side-by-side view
Loading...
/trunk/scripts/shells/mailbox.php Diff Switch to side-by-side view
Loading...
/trunk/scripts/shells/shell.php Diff Switch to side-by-side view
Loading...
/trunk/scripts/shells/alias.php to /trunk/model/CliHelp.php
--- a/trunk/scripts/shells/alias.php
+++ b/trunk/model/CliHelp.php
@@ -1,52 +1,63 @@
 <?php
 
+class CliHelp extends Shell {
 
-class PostfixAdminAlias extends Shell {
-
-/**
- * Contains tasks to load and instantiate
- *
- * @var array
- * @access public
- */
-        var $tasks = array('Add', 'Update', 'Delete', 'View');
-
-
-
-
+    public $handler_to_use = "__not_set__";
 
 /**
  * Show help for this shell.
  *
  * @access public
  */
-        function help() {
-                $head  = "Usage: postfixadmin-cli alias <task> [<address>] [] [-m <method>]\n";
-                $head .= "-----------------------------------------------\n";
-                $head .= "Parameters:\n\n";
+    public function execute() {
+        $this->help();
+    }
 
-                $commands = array(
-                        'task' => "\t<task>\n" .
-                                                "\t\tAvailable values:\n\n".
-                                                "\t\t".sprintf("%-20s %s", "view: ",  "View an existing alias.")."\n".
-                                                "\t\t".sprintf("%-20s %s", "add: ",  "Adds an alias.")."\n".
-                                                "\t\t".sprintf("%-20s %s", "update: ",  "Updates an alias.")."\n".
-                                                "\t\t".sprintf("%-20s %s", "delete: ",  "Deletes an alias")."\n",
-                        'address' => "\t[<address>]\n" .
-                                                "\t\tA address of recipient.\n",
-                );
+    public function help() {
 
-                $this->out($head);
-                if (!isset($this->args[1])) {
-                        foreach ($commands as $cmd) {
-                                $this->out("{$cmd}\n\n");
-                        }
-                } elseif (isset($commands[strtolower($this->args[1])])) {
-                        $this->out($commands[strtolower($this->args[1])] . "\n\n");
-                } else {
-                        $this->out("Command '" . $this->args[1] . "' not found");
-                }
+        $handler = new $this->handler_to_use;
+        # TODO: adjust help text according to $handler->taskNames
+
+        $module = preg_replace('/Handler$/', '', $this->handler_to_use);
+        $module = strtolower($module);
+
+        $this->out(
+"Usage:
+
+    postfixadmin-cli $module <task> [<address>] [--option value]
+");
+/*
+        View $module in interactive mode.
+
+- or -
+
+    postfixadmin-cli $module view <address>
+
+        View $module <address> in non-interactive mode.
+"); */
+ 
+
+
+        $head  = "Usage: postfixadmin-cli $module <task> [<address>] [--option value] [--option value]\n";
+        $head .= "-----------------------------------------------\n";
+        $head .= "Parameters:\n\n";
+
+        $commands = array(
+            'task' => "\t<task>\n" .
+                        "\t\tAvailable values:\n\n".
+                        "\t\t".sprintf("%-20s %s", "view: ",  "View an existing $module.")."\n".
+                        "\t\t".sprintf("%-20s %s", "add: ",  "Add a $module.")."\n".
+                        "\t\t".sprintf("%-20s %s", "update: ",  "Update a $module.")."\n".
+                        "\t\t".sprintf("%-20s %s", "delete: ",  "Delete a $module")."\n".
+                        "\t\t".sprintf("%-20s %s", "password: ",  "Changes the password for a $module")."\n",
+            'address' => "\t[<address>]\n" .
+                        "\t\tA address of recipient.\n",
+        );
+
+        foreach ($commands as $cmd) {
+            $this->out("{$cmd}\n\n");
         }
+    }
 
 
 }