From 0f2fe83c305c94c5351a67f929970ad0659e76b8 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Sat, 18 Jan 2014 00:07:56 -0600
Subject: [PATCH] Allow complex specification of arguments

Allow arguments to have sub-command 'options', so an argument like 'action'
can have a specified list of values, each with respective help output.
---
 setup/cli/modules/class.module.php | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/setup/cli/modules/class.module.php b/setup/cli/modules/class.module.php
index 421e49bd1..a1647ce3c 100644
--- a/setup/cli/modules/class.module.php
+++ b/setup/cli/modules/class.module.php
@@ -157,8 +157,18 @@ class Module {
         if ($this->arguments) {
             echo "\nArguments:\n";
             foreach ($this->arguments as $name=>$help)
+                $extra = '';
+                if (is_array($help)) {
+                    if (isset($help['options']) && is_array($help['options'])) {
+                        foreach($help['options'] as $op=>$desc)
+                            $extra .= wordwrap(
+                                "\n        $op - $desc", 76, "\n            ");
+                    }
+                    $help = $help['help'];
+                }
                 echo $name . "\n    " . wordwrap(
-                    preg_replace('/\s+/', ' ', $help), 76, "\n    ");
+                    preg_replace('/\s+/', ' ', $help), 76, "\n    ")
+                        .$extra."\n";
         }
 
         if ($this->epilog) {
@@ -198,6 +208,10 @@ class Module {
         foreach (array_keys($this->arguments) as $idx=>$name)
             if (!isset($this->_args[$idx]))
                 $this->optionError($name . " is a required argument");
+            elseif (is_array($this->arguments[$name])
+                    && isset($this->arguments[$name]['options'])
+                    && !isset($this->arguments[$name]['options'][$this->_args[$idx]]))
+                $this->optionError($name . " does not support such a value");
             else
                 $this->_args[$name] = &$this->_args[$idx];
 
-- 
GitLab