-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path__init__.py
More file actions
71 lines (51 loc) · 1.96 KB
/
__init__.py
File metadata and controls
71 lines (51 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import os
import click
import click_shell
from stackdio.cli.mixins import blueprints, formulas, stacks
from stackdio.cli.utils import pass_client
from stackdio.client import StackdioClient
from stackdio.client.config import CFG_DIR
from stackdio.client.version import __version__
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click_shell.shell(context_settings=CONTEXT_SETTINGS, prompt='stackdio > ',
intro='stackdio-cli, v{0}'.format(__version__))
@click.version_option(__version__, '-v', '--version')
@click.option('-c', '--config-dir', help='The config directory to use.',
type=click.Path(dir_okay=True, file_okay=False), default=CFG_DIR,
envvar='STACKDIO_CONFIG_DIR')
@click.pass_context
def stackdio(ctx, config_dir):
# Create a client instance
client = StackdioClient(cfg_file=os.path.join(config_dir, 'client.cfg'))
# Set this hist file
ctx.command.hist_file = os.path.join(config_dir, 'cli-history')
# Throw an error if we're not configured already
if ctx.invoked_subcommand not in ('configure', None) and not client.usable():
raise click.UsageError('It looks like you haven\'t used this CLI before. Please run '
'`stackdio-cli configure`')
# Put the client in the obj so other commands can pick it up
ctx.obj = client
@stackdio.command(name='configure')
@pass_client
def configure(client):
"""
Configure the client
"""
client.config.prompt_for_config()
@stackdio.command(name='server-version')
@pass_client
def server_version(client):
"""
Print the version of the server
"""
click.echo('stackdio-server, version {0}'.format(client.get_version()))
# Add all our other commands
stackdio.add_command(blueprints.blueprints)
stackdio.add_command(stacks.stacks)
stackdio.add_command(formulas.formulas)
def main():
# Just run our CLI tool
stackdio()
if __name__ == '__main__':
main()