1 | <?php |
||
8 | class CLI_Module { |
||
9 | |||
10 | var $name; |
||
11 | var $description; |
||
12 | var $params; |
||
13 | function CLI_Module($name, $description) { |
||
14 | $this->name = $name; |
||
15 | $this->description = $description; |
||
16 | $this->params = array(); |
||
17 | $this->actions = array(); |
||
18 | } |
||
19 | function getName() { |
||
32 | function execute($params) { |
||
33 | $result = null; |
||
42 | |||
43 | function help() { |
||
55 | /** |
||
56 | * getParameter - Get a specified parameter from the command line. |
||
57 | * |
||
58 | * extracted from GForge Command-line Interface |
||
59 | * contained in GForge. |
||
60 | * Copyright 2005 GForge, LLC |
||
61 | * http://gforge.org/ |
||
62 | * |
||
63 | * Given an array of parameters passed by the command line, this function |
||
64 | * searches the specified parameter in that array. |
||
65 | * For example, if we want the "name" parameter in the following command: |
||
66 | * $ ./script --name="john" --lastname="doe" |
||
67 | * this function will return the string "john". |
||
68 | * There is an option to give aliases for a certain parameter. For example, these |
||
69 | * commands can be equivalent: |
||
70 | * $ ./script -n "john" --lastname="doe" |
||
71 | * $ ./script --name="john" --lastname="doe" |
||
72 | * $ ./script -n "john" -l "doe" |
||
73 | * This is done by passing an array to the parameter "name". |
||
74 | * In the case of "flags", this function returns "true" is the flag is specified, |
||
75 | * for instance: |
||
76 | * $ ./script -v |
||
77 | * $ ./script --verbose |
||
78 | * This function also detects when several flags are grouped into one, for example: |
||
79 | * $ ./script -abc |
||
80 | * instead of |
||
81 | * $ ./script -a -b -c |
||
82 | * (this only works with one-character flags) |
||
83 | * Note that parameter names with more than one character are assumed to be preceded by |
||
84 | * "--" (like in "--name") parameters with one character are assumed to be preceded by |
||
85 | * a single "-" (like in "-n") |
||
86 | * |
||
87 | * @param array Array of parameters where we should look |
||
88 | * @param mixed A string that specifies the name of the parameter to look for, or an |
||
89 | * array of aliases (ej: array("name", "n")) |
||
90 | * @param bool Indicate if the parameter MUST have a value associated to it, and that it is |
||
91 | * not just a flag. This can also be seen as "isn't a flag" value |
||
92 | */ |
||
93 | |||
94 | function getParameter(&$parameter_array, $parameter, $require_value=false) { |
||
154 | /** |
||
155 | * get_user_input - Receive input from the user |
||
156 | * |
||
157 | * extracted from GForge Command-line Interface |
||
158 | * contained in GForge. |
||
159 | * Copyright 2005 GForge, LLC |
||
160 | * http://gforge.org/ |
||
161 | * |
||
162 | * @param string Text to show to the user |
||
163 | * @param bool Specify if input shouldn't be shown (useful when asking for passwords) |
||
164 | */ |
||
165 | function get_user_input($text, $hide=false) { |
||
178 | |||
179 | } |
||
180 | |||
181 | ?> |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: