forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
48 lines (38 loc) · 1.44 KB
/
__init__.py
File metadata and controls
48 lines (38 loc) · 1.44 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
"""Manages Object Storage S3 Credentials."""
# :license: MIT, see LICENSE for more details.
import importlib
import os
import click
CONTEXT = {'help_option_names': ['-h', '--help'],
'max_content_width': 999}
class CapacityCommands(click.MultiCommand):
"""Loads module for object storage S3 credentials related commands."""
def __init__(self, **attrs):
click.MultiCommand.__init__(self, **attrs)
self.path = os.path.dirname(__file__)
# pylint: disable=unused-argument
def list_commands(self, ctx):
"""List all sub-commands."""
commands = []
for filename in os.listdir(self.path):
if filename == '__init__.py':
continue
if filename.endswith('.py'):
commands.append(filename[:-3].replace("_", "-"))
commands.sort()
return commands
# pylint: disable=unused-argument
def get_command(self, ctx, cmd_name):
"""Get command for click."""
path = "%s.%s" % (__name__, cmd_name)
path = path.replace("-", "_")
try:
module = importlib.import_module(path)
return getattr(module, 'cli')
except ModuleNotFoundError as ex:
print(ex.name)
return None
# Required to get the sub-sub-sub command to work.
@click.group(cls=CapacityCommands, context_settings=CONTEXT)
def cli():
"""Base command for all object storage credentials S3 related concerns"""