Skip to content

Commit

Permalink
Refactor a bit of cli.py & implement #165, fixes #165
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Aug 27, 2014
1 parent 32c9742 commit e5361bf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions invoke/cli.py
Expand Up @@ -274,6 +274,15 @@ def derive_opts(args):
run['echo'] = True
return {'run': run}

def tasks_from_contexts(parser_contexts, collection):
tasks = []
for context in parser_contexts:
tasks.append((context.name, context.as_kwargs))
# Handle top level default task (like 'make')
if not tasks:
tasks = [(collection.default, {})]
return tasks

def dispatch(argv, version=None):
try:
args, collection, parser_contexts = parse(argv, version=version)
Expand All @@ -283,9 +292,7 @@ def dispatch(argv, version=None):
return sys.exit(e.code)
executor = Executor(collection, Context(**derive_opts(args)))
try:
tasks = []
for context in parser_contexts:
tasks.append((context.name, context.as_kwargs))
tasks = tasks_from_contexts(parser_contexts, collection)
dedupe = not args['no-dedupe'].value
return executor.execute(*tasks, dedupe=dedupe)
except Failure as f:
Expand Down

0 comments on commit e5361bf

Please sign in to comment.