Skip to content

Commit c073542

Browse files
author
Clark Perkins
committed
Change from pass_obj to pass_client
1 parent abf1315 commit c073542

File tree

8 files changed

+104
-97
lines changed

8 files changed

+104
-97
lines changed

stackdio/cli/__init__.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import click
88

99
from stackdio.cli.mixins import blueprints, bootstrap, formulas, stacks
10+
from stackdio.cli.utils import pass_client
1011
from stackdio.client import StackdioClient
1112
from stackdio.client.version import __version__
1213

@@ -26,26 +27,24 @@ def stackdio(ctx):
2627
'`stackdio-cli configure`')
2728

2829
# Put the client in the obj
29-
ctx.obj['client'] = client
30+
ctx.obj = client
3031

3132

3233
@stackdio.command()
33-
@click.pass_obj
34-
def configure(obj):
34+
@pass_client
35+
def configure(client):
3536
"""
3637
Configure the client
3738
"""
38-
client = obj['client']
39-
print('configuring')
39+
click.echo('configuring')
4040

4141

4242
@stackdio.command('server-version')
43-
@click.pass_obj
44-
def server_version(obj):
43+
@pass_client
44+
def server_version(client):
4545
"""
4646
Print the version of the server
4747
"""
48-
client = obj['client']
4948
click.echo('stackdio-server, version {0}'.format(client.get_version()))
5049

5150

@@ -57,7 +56,7 @@ def server_version(obj):
5756

5857
def main():
5958
# Just run our CLI tool
60-
stackdio(obj={})
59+
stackdio()
6160

6261

6362
if __name__ == '__main__':

stackdio/cli/mixins/blueprints.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import yaml
77

88
from stackdio.cli.blueprints.generator import BlueprintGenerator, BlueprintException
9-
from stackdio.cli.utils import print_summary
9+
from stackdio.cli.utils import print_summary, pass_client
1010

1111

1212
class BlueprintNotFound(Exception):
@@ -22,13 +22,11 @@ def blueprints():
2222

2323

2424
@blueprints.command(name='list')
25-
@click.pass_obj
26-
def list_blueprints(obj):
25+
@pass_client
26+
def list_blueprints(client):
2727
"""
2828
List all blueprints
2929
"""
30-
client = obj['client']
31-
3230
click.echo('Getting blueprints ... ')
3331
print_summary('Blueprint', client.list_blueprints())
3432

@@ -45,13 +43,11 @@ def _recurse_dir(dirname, extensions, prefix=''):
4543

4644

4745
@blueprints.command(name='list-templates')
48-
@click.pass_obj
49-
def list_templates(obj):
46+
@pass_client
47+
def list_templates(client):
5048
"""
5149
List all the blueprint templates
5250
"""
53-
client = obj['client']
54-
5551
if 'blueprint_dir' not in client.config:
5652
click.echo('Missing blueprint directory config')
5753
return
@@ -107,7 +103,7 @@ def _create_single_blueprint(config, template_file, var_files, no_prompt):
107103

108104

109105
@blueprints.command(name='create')
110-
@click.pass_obj
106+
@pass_client
111107
@click.option('-m', '--mapping',
112108
help='The entry in the map file to use')
113109
@click.option('-t', '--template',
@@ -118,12 +114,10 @@ def _create_single_blueprint(config, template_file, var_files, no_prompt):
118114
'var files will override those in var files to the left.')
119115
@click.option('-n', '--no-prompt', is_flag=True, default=True,
120116
help='Don\'t prompt for missing variables in the template')
121-
def create_blueprint(obj, mapping, template, var_file, no_prompt):
117+
def create_blueprint(client, mapping, template, var_file, no_prompt):
122118
"""
123119
Create a blueprint
124120
"""
125-
client = obj['client']
126-
127121
if not template and not mapping:
128122
raise click.UsageError('You must specify either a template or a mapping.')
129123

@@ -157,14 +151,12 @@ def create_blueprint(obj, mapping, template, var_file, no_prompt):
157151

158152

159153
@blueprints.command(name='create-all')
160-
@click.pass_obj
154+
@pass_client
161155
@click.confirmation_option('-y', '--yes', prompt='Really create all blueprints?')
162-
def create_all_blueprints(obj):
156+
def create_all_blueprints(client):
163157
"""
164158
Create all the blueprints in the map file
165159
"""
166-
client = obj['client']
167-
168160
blueprint_dir = os.path.expanduser(client.config['blueprint_dir'])
169161
mapping = yaml.safe_load(open(os.path.join(blueprint_dir, 'mappings.yaml'), 'r'))
170162

@@ -190,14 +182,12 @@ def get_blueprint_id(client, blueprint_title):
190182

191183

192184
@blueprints.command(name='delete')
193-
@click.pass_obj
185+
@pass_client
194186
@click.argument('title')
195-
def delete_blueprint(obj, title):
187+
def delete_blueprint(client, title):
196188
"""
197189
Delete a blueprint
198190
"""
199-
client = obj['client']
200-
201191
blueprint_id = get_blueprint_id(client, title)
202192

203193
click.confirm('Really delete blueprint {0}?'.format(title), abort=True)
@@ -207,15 +197,13 @@ def delete_blueprint(obj, title):
207197

208198

209199
@blueprints.command(name='delete-all')
210-
@click.pass_obj
200+
@pass_client
211201
@click.confirmation_option('-y', '--yes', prompt='Really delete all blueprints? This is '
212202
'completely destructive, and you will never get them back.')
213-
def delete_all_blueprints(obj):
203+
def delete_all_blueprints(client):
214204
"""
215205
Delete all blueprints
216206
"""
217-
client = obj['client']
218-
219207
for blueprint in client.list_blueprints():
220208
client.delete_blueprint(blueprint['id'])
221209
click.secho('Deleted blueprint {0}'.format(blueprint['title']), fg='magenta')

stackdio/cli/mixins/bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import keyring
1313
import yaml
1414

15-
from stackdio.cli.polling import poll_and_wait, TimeoutException
15+
from stackdio.cli.utils import TimeoutException, poll_and_wait
1616

1717

1818
class PublicKeyNotFound(Exception):

stackdio/cli/mixins/formulas.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import click
44

5-
from stackdio.cli.utils import print_summary
5+
from stackdio.cli.utils import pass_client, print_summary
66

77

88
@click.group()
@@ -14,8 +14,8 @@ def formulas():
1414

1515

1616
@formulas.command(name='list')
17-
@click.pass_obj
18-
def list_formulas(obj):
17+
@pass_client
18+
def list_formulas(client):
1919
"""
2020
List all formulas
2121
"""
@@ -26,12 +26,12 @@ def list_formulas(obj):
2626

2727

2828
@formulas.command(name='import')
29-
@click.pass_obj
29+
@pass_client
3030
@click.argument('uri')
3131
@click.option('-u', '--username', type=click.STRING, help='Git username')
3232
@click.option('-p', '--password', type=click.STRING, prompt=True, hide_input=True,
3333
help='Git password')
34-
def import_formula(obj, uri, username, password):
34+
def import_formula(client, uri, username, password):
3535
"""
3636
Import a formula
3737
"""
@@ -56,9 +56,9 @@ def get_formula_id(client, formula_uri):
5656

5757

5858
@formulas.command(name='delete')
59-
@click.pass_obj
59+
@pass_client
6060
@click.argument('uri')
61-
def delete_formula(obj, uri):
61+
def delete_formula(client, uri):
6262
"""
6363
Delete a formula
6464
"""

stackdio/cli/mixins/stacks.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import click
44

55
from stackdio.cli.mixins.blueprints import get_blueprint_id
6-
from stackdio.cli.polling import poll_and_wait
7-
from stackdio.cli.utils import print_summary
6+
from stackdio.cli.utils import pass_client, print_summary, poll_and_wait
87
from stackdio.client.exceptions import StackException
98

109

@@ -20,8 +19,8 @@ def stacks():
2019

2120

2221
@stacks.command(name='list')
23-
@click.pass_obj
24-
def list_stacks(obj):
22+
@pass_client
23+
def list_stacks(client):
2524
"""
2625
List all stacks
2726
"""
@@ -32,10 +31,10 @@ def list_stacks(obj):
3231

3332

3433
@stacks.command(name='launch')
35-
@click.pass_obj
34+
@pass_client
3635
@click.argument('blueprint_title')
3736
@click.argument('stack_title')
38-
def launch_stack(obj, blueprint_title, stack_title):
37+
def launch_stack(client, blueprint_title, stack_title):
3938
"""
4039
Launch a stack from a blueprint
4140
"""
@@ -68,10 +67,10 @@ def get_stack_id(client, stack_title):
6867

6968

7069
@stacks.command(name='history')
71-
@click.pass_obj
70+
@pass_client
7271
@click.argument('stack_title')
7372
@click.option('-l', '--length', type=click.INT, default=20, help='The number of entries to show')
74-
def stack_history(obj, stack_title, length):
73+
def stack_history(client, stack_title, length):
7574
"""
7675
Print recent history for a stack
7776
"""
@@ -84,9 +83,9 @@ def stack_history(obj, stack_title, length):
8483

8584

8685
@stacks.command(name='hostnames')
87-
@click.pass_obj
86+
@pass_client
8887
@click.argument('stack_title')
89-
def stack_hostnames(obj, stack_title):
88+
def stack_hostnames(client, stack_title):
9089
"""
9190
Print hostnames for a stack
9291
"""
@@ -101,9 +100,9 @@ def stack_hostnames(obj, stack_title):
101100

102101

103102
@stacks.command(name='delete')
104-
@click.pass_obj
103+
@pass_client
105104
@click.argument('stack_title')
106-
def delete_stack(obj, stack_title):
105+
def delete_stack(client, stack_title):
107106
"""
108107
Delete a stack. PERMANENT AND DESTRUCTIVE!!!
109108
"""
@@ -120,10 +119,10 @@ def delete_stack(obj, stack_title):
120119

121120

122121
@stacks.command(name='action')
123-
@click.pass_obj
122+
@pass_client
124123
@click.argument('stack_title')
125124
@click.argument('action')
126-
def perform_action(obj, stack_title, action):
125+
def perform_action(client, stack_title, action):
127126
"""
128127
Perform an action on a stack
129128
"""
@@ -195,9 +194,9 @@ def check_status():
195194

196195

197196
@stacks.command(name='command-output')
198-
@click.pass_obj
197+
@pass_client
199198
@click.argument('command_id')
200-
def get_command_output(obj, command_id):
199+
def get_command_output(client, command_id):
201200
"""
202201
Get the status and output of a command
203202
"""
@@ -227,9 +226,9 @@ def print_logs(client, stack_id):
227226

228227

229228
@stacks.command(name='list-logs')
230-
@click.pass_obj
229+
@pass_client
231230
@click.argument('stack_title')
232-
def list_stack_logs(obj, stack_title):
231+
def list_stack_logs(client, stack_title):
233232
"""
234233
Get a list of stack logs
235234
"""
@@ -241,11 +240,11 @@ def list_stack_logs(obj, stack_title):
241240

242241

243242
@stacks.command(name='logs')
244-
@click.pass_obj
243+
@pass_client
245244
@click.argument('stack_title')
246245
@click.argument('log_type')
247246
@click.option('-l', '--lines', type=click.INT, default=25, help='number of lines to tail')
248-
def stack_logs(obj, stack_title, log_type, lines):
247+
def stack_logs(client, stack_title, log_type, lines):
249248
"""
250249
Get logs for a stack
251250
"""

stackdio/cli/polling.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)