Skip to content

Commit f9b0078

Browse files
author
Clark Perkins
committed
Moved a couple things to click-shell
1 parent 0a3e0c8 commit f9b0078

File tree

4 files changed

+35
-151
lines changed

4 files changed

+35
-151
lines changed

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ def test_python_version():
5050
'Jinja2==2.7.3',
5151
'PyYAML==3.11',
5252
'click>=6.0,<7.0',
53-
'cmd2>=0.6,<0.7',
53+
'click-shell==0.1',
5454
'keyring==3.7',
55-
'readline',
5655
'requests>=2.4.0,<2.6.0',
5756
'simplejson==3.4.0',
5857
]

stackdio/cli/__init__.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from cmd import Cmd
99

1010
import click
11+
import click_shell
1112
import keyring
1213
from requests import ConnectionError
1314

1415
from stackdio.cli import mixins
15-
from stackdio.cli.shell import get_shell
1616
from stackdio.client import StackdIO
1717
from stackdio.client.config import StackdioConfig
1818
from stackdio.client.exceptions import MissingConfigException
@@ -21,6 +21,7 @@
2121

2222
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
2323

24+
HIST_FILE = os.path.join(os.path.expanduser('~'), '.stackdio-cli', 'history')
2425

2526
KEYRING_SERVICE = 'stackdio_cli'
2627

@@ -53,20 +54,17 @@ class StackdioObj(object):
5354
def __init__(self, ctx, fail_on_misconfigure):
5455
super(StackdioObj, self).__init__()
5556
self.config = load_config(fail_on_misconfigure)
56-
self.shell = get_shell(ctx)
5757
if self.config:
5858
self.client = get_client(self.config)
5959

6060

61-
@click.group(context_settings=CONTEXT_SETTINGS, invoke_without_command=True)
61+
@click_shell.shell(prompt='stackdio > ', intro='stackdio shell v{0}'.format(__version__),
62+
hist_file=HIST_FILE, context_settings=CONTEXT_SETTINGS)
6263
@click.version_option(__version__, '-v', '--version')
6364
@click.pass_context
6465
def stackdio(ctx):
6566
ctx.obj = StackdioObj(ctx, ctx.invoked_subcommand != 'configure')
6667

67-
if ctx.invoked_subcommand is None:
68-
ctx.obj.shell.cmdloop()
69-
7068

7169
@stackdio.group()
7270
def stacks():
@@ -75,12 +73,17 @@ def stacks():
7573

7674
@stackdio.group()
7775
def blueprints():
78-
"""
79-
Foo bar
80-
"""
8176
pass
8277

8378

79+
@blueprints.command()
80+
@click.option('--template', '-t')
81+
@click.option('--var-file', '-v', multiple=True)
82+
def create(template, var_file):
83+
click.echo(template)
84+
click.echo(var_file)
85+
86+
8487
@stackdio.group()
8588
def formulas():
8689
pass
@@ -96,8 +99,9 @@ def configure():
9699

97100

98101
@stackdio.command('server-version')
99-
def server_version():
100-
client = get_client()
102+
@click.pass_obj
103+
def server_version(obj):
104+
client = obj.client
101105
click.echo('stackdio-server, version {0}'.format(client.get_version()))
102106

103107

stackdio/cli/shell.py

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

stackdio/client/config.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@
3131

3232
class StackdioConfig(object):
3333

34+
BOOL_MAP = {
35+
str(True): True,
36+
str(False): False,
37+
}
38+
3439
def __init__(self, section='stackdio', config_file=CFG_FILE, create=False):
3540
super(StackdioConfig, self).__init__()
3641

42+
self.section = section
43+
3744
self._cfg_file = config_file
3845

3946
if not create and not os.path.isfile(config_file):
@@ -47,22 +54,28 @@ def __init__(self, section='stackdio', config_file=CFG_FILE, create=False):
4754
self._config.read(config_file)
4855

4956
# Make the blueprint dir usable
50-
new_blueprint_dir = os.path.expanduser(self.get('blueprint_dir'))
51-
self._config.set(section, 'blueprint_dir', new_blueprint_dir)
52-
53-
self.section = section
57+
blueprint_dir = self.get('blueprint_dir')
58+
if blueprint_dir:
59+
new_blueprint_dir = os.path.expanduser(blueprint_dir)
60+
self._config.set(section, 'blueprint_dir', new_blueprint_dir)
5461

5562
def save(self):
5663
with open(self._cfg_file, 'w') as f:
5764
self._config.write(f)
5865

5966
def __getitem__(self, item):
6067
try:
61-
return self._config.get(self.section, item)
68+
ret = self._config.get(self.section, item)
69+
if ret in self.BOOL_MAP:
70+
return self.BOOL_MAP[ret]
71+
else:
72+
return str(ret)
6273
except NoOptionError:
6374
raise KeyError(item)
6475

6576
def __setitem__(self, key, value):
77+
if isinstance(value, bool):
78+
value = str(value)
6679
self._config.set(self.section, key, value)
6780

6881
def get(self, item, default=None):
@@ -84,7 +97,7 @@ def _test_url(self, url):
8497
except ConnectionError:
8598
return False
8699
except MissingSchema:
87-
print("You might have forgotten http:// or https://")
100+
click.echo('You might have forgotten http:// or https://')
88101
return False
89102

90103
def get_url(self):

0 commit comments

Comments
 (0)