Skip to content

Commit

Permalink
add configurable banner to init command
Browse files Browse the repository at this point in the history
  • Loading branch information
rochacbruno committed Jun 11, 2016
1 parent e395a9e commit 4cf0df4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions manage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import readline
import importlib
import rlcompleter
from .template import manage_dict
from .template import default_manage_dict

MANAGE_FILE = 'manage.yml'
if os.path.exists(MANAGE_FILE):
with open(MANAGE_FILE) as manage_file:
manage_dict = yaml.load(manage_file)
else:
manage_dict = default_manage_dict


@click.group()
Expand All @@ -28,7 +33,8 @@ def __getattr__(self, item):


@core_cmd.command()
def init():
@click.option('--banner')
def init(banner):
"""Initialize a manage shell in current directory
$ manage init --banner="My awesome app shell"
initializing manage...
Expand All @@ -42,7 +48,8 @@ def init():
"Copy the file"

with open(MANAGE_FILE, 'w') as manage_file:
data = manage_dict
data = default_manage_dict
data['shell']['banner']['message'] = banner
manage_file.write(yaml.dump(data, default_flow_style=False))


Expand All @@ -56,9 +63,12 @@ def shell(ipython):
}
_vars.update(auto_imported)
banner_msg = (
'Welcome to PROGRAM interactive shell\n'
'\tAuto imported: {0}\n'
).format(auto_imported.keys())
'{banner_message}\n'
'\tAuto imported: {auto_imported}\n'
).format(
auto_imported=auto_imported.keys(),
banner_message=manage_dict['shell']['banner']['message']
)
readline.set_completer(rlcompleter.Completer(_vars).complete)
readline.parse_and_bind('tab: complete')
try:
Expand Down
2 changes: 1 addition & 1 deletion manage/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
manage_dict = {
default_manage_dict = {
'shell': {
'banner': {
'enabled': True,
Expand Down

0 comments on commit 4cf0df4

Please sign in to comment.