Skip to content

Commit 1f9dc15

Browse files
committed
Keeping dev documentation up-to-date
1 parent 7b5260e commit 1f9dc15

4 files changed

Lines changed: 18 additions & 30 deletions

File tree

SoftLayer/tests/CLI/modules/bmc_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ def test_get_default_value_returns_none_for_unknown_category(self):
278278
output = runnable._get_default_value(option_mock, 'nope')
279279
self.assertEqual(None, output)
280280

281-
@staticmethod
282-
def _setup_package_mocks(client):
281+
def _setup_package_mocks(self, client):
283282
p = client['Product_Package']
284283
p.getAllObjects = product_package_mock.getAllObjects_Mock()
285284
p.getConfiguration = product_package_mock.getConfiguration_Mock(True)

SoftLayer/tests/CLI/modules/server_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,7 @@ def test_get_default_value_returns_none_for_unknown_category(self):
606606
output = runnable._get_default_value(option_mock, 'nope')
607607
self.assertEqual(None, output)
608608

609-
@staticmethod
610-
def _setup_package_mocks(client):
609+
def _setup_package_mocks(self, client):
611610
package = client['Product_Package']
612611
package.getAllObjects = product_package_mock.getAllObjects_Mock()
613612
package.getConfiguration = product_package_mock.getConfiguration_Mock()

docs/dev/cli.rst

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,26 @@ There are some tenants for styling the doc blocks
4343

4444
Action
4545
------
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`.
4747

4848
::
4949

5050
class CLIRunnable(object):
51-
action = None
51+
options = [] # set by subclass
52+
action = None # set by subclass
5253

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
5657

57-
@staticmethod
58-
def execute(client, args):
58+
def execute(self, args):
5959
pass
6060

6161
The required interfaces are:
6262

6363
* The docblock (__doc__) for docopt
6464
* 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):
6966

7067
A minimal implementation for `sl example print` would look like this:
7168
::
@@ -79,8 +76,7 @@ A minimal implementation for `sl example print` would look like this:
7976

8077
action = 'print'
8178

82-
@staticmethod
83-
def execute(client, args):
79+
def execute(self, args):
8480
print "EXAMPLE!"
8581

8682

@@ -114,8 +110,7 @@ The `execute()` method is expected to return either `None` or an instance of `So
114110

115111
action = 'pretty'
116112

117-
@staticmethod
118-
def execute(client, args):
113+
execute(self, args):
119114
# create a table with two columns: col1, col2
120115
t = Table(['col1', 'col2'])
121116

@@ -168,8 +163,7 @@ Refer to docopt for more complete documentation
168163

169164
action = 'parse'
170165

171-
@staticmethod
172-
def execute(client, args):
166+
def execute(self, args):
173167
if args.get('--test'):
174168
print "Just testing, move along..."
175169
else:
@@ -189,7 +183,7 @@ Refer to docopt for more complete documentation
189183
Accessing the API
190184
-----------------
191185

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.
193187

194188
Confirmations
195189
-------------
@@ -212,8 +206,7 @@ All confirmations should be easily bypassed by checking for `args['--really']`.
212206
action = 'parse'
213207
options = ['confirm'] # confirm adds the '-y|--really' options and help
214208

215-
@staticmethod
216-
def execute(client, args):
209+
def execute(self, args):
217210
pass
218211

219212
There are two primary confirmation prompts that both leverage `SoftLayer.CLI.valid_response`:

docs/dev/example_module.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Example CLI Module
3131

3232
action = 'print'
3333

34-
@staticmethod
35-
def execute(client, args):
34+
def execute(self, args):
3635
print "EXAMPLE!"
3736

3837

@@ -45,8 +44,7 @@ Example CLI Module
4544

4645
action = 'pretty'
4746

48-
@staticmethod
49-
def execute(client, args):
47+
def execute(self, args):
5048
# create a table with two columns: col1, col2
5149
t = Table(['col1', 'col2'])
5250

@@ -77,8 +75,7 @@ Example CLI Module
7775
action = 'parse'
7876
options = ['confirm']
7977

80-
@staticmethod
81-
def execute(client, args):
78+
def execute(self, args):
8279
if args.get('--test'):
8380
print "Just testing, move along..."
8481
else:

0 commit comments

Comments
 (0)