You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dev/cli.rst
+13-20Lines changed: 13 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,29 +43,26 @@ There are some tenants for styling the doc blocks
43
43
44
44
Action
45
45
------
46
-
Actions are implemented using classes in the module that subclass `SoftLayer.CLI.CLIRunnable`. The actual class name is irrelevant for the implementation details as it isn't used anywhere. The docblock is used as the arguement parser as well. Unlike the modules docblock, additional, common, arguments are added to the end as well; i.e. `--config` and `--format`.
46
+
Actions are implemented using classes in the module that subclass `SoftLayer.CLI.CLIRunnable`. The actual class name is irrelevant for the implementation details as it isn't referenced anywhere. The docblock is used as the arguement parser as well. Unlike the modules docblock extra, common-used arguments are added to the end as well; i.e. `--config` and `--format`.
47
47
48
48
::
49
49
50
50
class CLIRunnable(object):
51
-
action = None
51
+
options = [] # set by subclass
52
+
action = None # set by subclass
52
53
53
-
@staticmethod
54
-
def add_additional_args(parser):
55
-
pass
54
+
def __init__(self, client=None, env=None):
55
+
self.client = client
56
+
self.env = env
56
57
57
-
@staticmethod
58
-
def execute(client, args):
58
+
def execute(self, args):
59
59
pass
60
60
61
61
The required interfaces are:
62
62
63
63
* The docblock (__doc__) for docopt
64
64
* action class attribute
65
-
* def execute(client, args)
66
-
67
-
- Don't forget the @staticmethod annotation!
68
-
- you can also use @classmethod and use execute(cls, client, args) if you plan on dispatching instead of executing a simple task.
65
+
* def execute(self, args):
69
66
70
67
A minimal implementation for `sl example print` would look like this:
71
68
::
@@ -79,8 +76,7 @@ A minimal implementation for `sl example print` would look like this:
79
76
80
77
action = 'print'
81
78
82
-
@staticmethod
83
-
def execute(client, args):
79
+
def execute(self, args):
84
80
print "EXAMPLE!"
85
81
86
82
@@ -114,8 +110,7 @@ The `execute()` method is expected to return either `None` or an instance of `So
114
110
115
111
action = 'pretty'
116
112
117
-
@staticmethod
118
-
def execute(client, args):
113
+
execute(self, args):
119
114
# create a table with two columns: col1, col2
120
115
t = Table(['col1', 'col2'])
121
116
@@ -168,8 +163,7 @@ Refer to docopt for more complete documentation
168
163
169
164
action = 'parse'
170
165
171
-
@staticmethod
172
-
def execute(client, args):
166
+
def execute(self, args):
173
167
if args.get('--test'):
174
168
print "Just testing, move along..."
175
169
else:
@@ -189,7 +183,7 @@ Refer to docopt for more complete documentation
189
183
Accessing the API
190
184
-----------------
191
185
192
-
API access is available via the first argument of `execute` which will be an initialized copy of `SoftLayer.API.Client`. Please refer to [using the api](API-Usage) for further details on howto use the `Client` object.
186
+
API access is available via an attribute of the CLIRunnable instance called. In execute(), for example, you can refer to `self.client` to access an instanciated instance of `SoftLayer.API.Client`. Please refer to [using the api](API-Usage) for further details on howto use the `Client` object.
193
187
194
188
Confirmations
195
189
-------------
@@ -212,8 +206,7 @@ All confirmations should be easily bypassed by checking for `args['--really']`.
212
206
action = 'parse'
213
207
options = ['confirm'] # confirm adds the '-y|--really' options and help
214
208
215
-
@staticmethod
216
-
def execute(client, args):
209
+
def execute(self, args):
217
210
pass
218
211
219
212
There are two primary confirmation prompts that both leverage `SoftLayer.CLI.valid_response`:
0 commit comments