Skip to content

Commit

Permalink
Re #56, tweak nested output & clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Jun 21, 2011
1 parent b2b27ac commit 9d3280b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
7 changes: 6 additions & 1 deletion fabric/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ def _nested_list(mapping, level=1):
result.extend(_nested_list(module, level + 1))
return result

COMMANDS_HEADER = "Available commands"
NESTED_REMINDER = " (remember to call as module.[...].task)"

def list_commands(docstring, format_):
"""
Expand All @@ -408,7 +410,10 @@ def list_commands(docstring, format_):
if docstring:
trailer = "\n" if not docstring.endswith("\n") else ""
result.append(docstring + trailer)
result.append("Available commands:\n")
header = COMMANDS_HEADER
if format_ == "nested":
header += NESTED_REMINDER
result.append(header + ":\n")
c = _normal_list() if format_ == "normal" else _nested_list(state.commands)
result.extend(c)
return result
Expand Down
22 changes: 9 additions & 13 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from fabric.decorators import hosts, roles, task
from fabric.main import (get_hosts, parse_arguments, _merge, _escape_split,
load_fabfile, list_commands, _task_names, _crawl, crawl)
load_fabfile, list_commands, _task_names, _crawl, crawl,
COMMANDS_HEADER, NESTED_REMINDER)

import fabric.state
from fabric.state import _AttributeDict
Expand Down Expand Up @@ -389,22 +390,17 @@ def list_output(module, format_, expected):
eq_output(docstring, format_, expected)

def test_list_output():
lead = ":\n\n "
normal_head = COMMANDS_HEADER + lead
nested_head = COMMANDS_HEADER + NESTED_REMINDER + lead
for desc, module, format_, expected in (
("shorthand (& with namespacing)", 'deep', 'short', "submodule.subsubmodule.deeptask"),
("normal (& with namespacing)", 'deep', 'normal', """Available commands:
submodule.subsubmodule.deeptask"""),
("normal (with docstring)", 'docstring', 'normal', """Available commands:
foo Foos!"""),
("nested (leaf only)", 'deep', 'nested', """Available commands:
submodule:
("normal (& with namespacing)", 'deep', 'normal', normal_head + "submodule.subsubmodule.deeptask"),
("normal (with docstring)", 'docstring', 'normal', normal_head + "foo Foos!"),
("nested (leaf only)", 'deep', 'nested', nested_head + """submodule:
subsubmodule:
deeptask"""),
("nested (full)", 'tree', 'nested', """Available commands:
build_docs
("nested (full)", 'tree', 'nested', nested_head + """build_docs
deploy
db:
migrate
Expand Down

0 comments on commit 9d3280b

Please sign in to comment.