Revision 59cadffb docs/developers/adding-commands.rst
b/docs/developers/adding-commands.rst | ||
---|---|---|
85 | 85 |
|
86 | 86 |
def command(cmd_tree, prefix='', descedants_depth=None): |
87 | 87 |
"""Load a class as a command |
88 |
@cmd_tree is the CommandTree to be updated with a new command
|
|
89 |
@prefix of the commands allowed to be inserted ('' for all)
|
|
90 |
@descedants_depth is the depth of the tree descedants of the
|
|
88 |
:param cmd_tree: is the CommandTree to be updated with a new command
|
|
89 |
:param prefix: of the commands allowed to be inserted ('' for all)
|
|
90 |
:param descedants_depth: is the depth of the tree descedants of the
|
|
91 | 91 |
prefix command. |
92 | 92 |
""" |
93 | 93 |
|
... | ... | |
125 | 125 |
Declare run-time argument |
126 | 126 |
------------------------- |
127 | 127 |
|
128 |
The argument mechanism allows the definition of run-time arguments. Some basic argument types are defined at the `argument module <cli.html#module-kamaki.cli.argument>`_, but it is not uncommon to extent these classes in order to achieve specialized type checking and syntax control (e.g. at `pithos_cli module <cli.html#module-kamaki.cli.commands.pithos_cli>`_).
|
|
128 |
The argument mechanism allows the definition of run-time arguments. Some basic argument types are defined at the `argument module <code.html#module-kamaki.cli.argument>`_, but it is not uncommon to extent these classes in order to achieve specialized type checking and syntax control (e.g. at `pithos_cli module <code.html#module-kamaki.cli.commands.pithos_cli>`_).
|
|
129 | 129 |
|
130 | 130 |
To declare a run-time argument on a specific command, the object class should initialize a dict called *arguments* , where Argument objects are stored. Each argument object is a possible run-time argument. Syntax checking happens at client level, while the type checking is implemented in the Argument code (thus, many different Argument types might be needed). |
131 | 131 |
|
... | ... | |
138 | 138 |
class mygrp1_list_details(): |
139 | 139 |
"""list of details""" |
140 | 140 |
|
141 |
def __init__(self, global_args={}) |
|
141 |
def __init__(self, global_args={}):
|
|
142 | 142 |
global_args['match'] = ValueArgument( |
143 | 143 |
'Filter results to match string', |
144 | 144 |
'--match') |
... | ... | |
149 | 149 |
|
150 | 150 |
The command behavior for each command / class is coded in *main*. The parameters of *main* method defines the command parameters part of the syntax. In specific:: |
151 | 151 |
|
152 |
main(self, param) - obligatory parameter |
|
153 |
main(self, param=None) - optional parameter |
|
152 |
main(self, param) - obligatory parameter <param>
|
|
153 |
main(self, param=None) - optional parameter [param]
|
|
154 | 154 |
main(self, param1, param2=42) - <param1> [param2] |
155 | 155 |
main(self, param1____param2) - <param1:param2> |
156 | 156 |
main(self, param1____param2=[]) - [param1:param2] |
Also available in: Unified diff