forked from localstack/localstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalstack
More file actions
executable file
·94 lines (78 loc) · 2.72 KB
/
localstack
File metadata and controls
executable file
·94 lines (78 loc) · 2.72 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""
Command line interface (CLI) for LocalStack.
Usage:
localstack [options] <command> [ <args> ... ]
localstack (-v | --version)
localstack (-h | --help)
Commands:%s
Options:
-d --debug Show verbose debug output
-h --help Show this screen
-v --version Show version
%s
"""
import os
import sys
import glob
import json
import traceback
PARENT_FOLDER = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
venv_dir = os.path.join(PARENT_FOLDER, '.venv')
if os.path.isdir(venv_dir):
for path in glob.glob(os.path.join(venv_dir, 'lib/python*/site-packages')):
sys.path.insert(0, path)
sys.path.insert(0, PARENT_FOLDER)
from docopt import docopt
from localstack import config, constants
from localstack.utils import cli, bootstrap
if __name__ == '__main__':
# set basic CLI commands
config.CLI_COMMANDS['infra'] = {
'description': 'Commands to manage the infrastructure',
'function': cli.cmd_infra
}
config.CLI_COMMANDS['start'] = {
'description': 'Shorthand to start the infrastructure',
'function': cli.cmd_infra
}
config.CLI_COMMANDS['web'] = {
'description': 'Commands to manage the Web dashboard',
'function': cli.cmd_web
}
config.CLI_COMMANDS['ssh'] = {
'description': 'Shorthand to obtain a shell in the running container',
'function': cli.cmd_ssh
}
# load CLI plugins
bootstrap.load_plugins(scope=bootstrap.PLUGIN_SCOPE_COMMANDS)
# create final usage string
additional_params = []
additional_commands = ''
for cmd in sorted(config.CLI_COMMANDS.keys()):
cmd_details = config.CLI_COMMANDS[cmd]
additional_commands += '\n %s%s%s' % (cmd, (20 - len(cmd)) * ' ', cmd_details['description'])
for param in cmd_details.get('parameters', []):
additional_params.append(param)
additional_params = '\n'.join(additional_params)
doc_string = __doc__ % (additional_commands, additional_params)
args = docopt(doc_string, options_first=True)
if args['--version']:
print(constants.VERSION)
sys.exit(0)
if args['--debug']:
os.environ['DEBUG'] = '1'
# invoke subcommand
argv = [args['<command>']] + args['<args>']
subcommand = config.CLI_COMMANDS.get(args['<command>'])
if subcommand:
try:
subcommand['function'](argv, args)
except Exception as e:
if os.environ.get('DEBUG') in ['1', 'true']:
print(traceback.format_exc())
print('ERROR: %s' % e)
sys.exit(1)
else:
print('ERROR: Invalid command "%s"' % args['<command>'])
sys.exit(1)