Skip to content

Commit

Permalink
Revert "Display the default value of args in help #126"
Browse files Browse the repository at this point in the history
This reverts commit 9f7962b.
  • Loading branch information
nat-n authored Mar 22, 2023
1 parent c733f24 commit 506fa9b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 51 deletions.
5 changes: 2 additions & 3 deletions poethepoet/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .exceptions import ExecutionError, PoeException

if TYPE_CHECKING:

from .config import PoeConfig
from .context import RunContext
from .task import PoeTask
Expand Down Expand Up @@ -174,9 +175,7 @@ def print_help(
if isinstance(error, str):
error = PoeException(error)

tasks_help: Dict[
str, Tuple[str, Sequence[Tuple[Tuple[str, ...], str, str]]]
] = {
tasks_help: Dict[str, Tuple[str, Sequence[Tuple[Tuple[str, ...], str]]]] = {
task_name: (
(
content.get("help", ""),
Expand Down
11 changes: 2 additions & 9 deletions poethepoet/task/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,11 @@ def _get_arg_options_list(arg: ArgParams, name: Optional[str] = None):
@classmethod
def get_help_content(
cls, args_def: Optional[ArgsDef]
) -> List[Tuple[Tuple[str, ...], str, str]]:
) -> List[Tuple[Tuple[str, ...], str]]:
if args_def is None:
return []

def format_default(arg) -> str:
default = arg.get("default")
if default:
return f"[default: {default}]"
return ""

return [
(arg["options"], arg.get("help", ""), format_default(arg))
(arg["options"], arg.get("help", ""))
for arg in cls._normalize_args_def(args_def)
]

Expand Down
24 changes: 8 additions & 16 deletions poethepoet/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def set_default_verbosity(self, default_verbosity: int):
def print_help(
self,
tasks: Optional[
Mapping[str, Tuple[str, Sequence[Tuple[Tuple[str, ...], str, str]]]]
Mapping[str, Tuple[str, Sequence[Tuple[Tuple[str, ...], str]]]]
] = None,
info: Optional[str] = None,
error: Optional[PoeException] = None,
Expand Down Expand Up @@ -195,33 +195,25 @@ def print_help(
max_task_len = max(
max(
len(task),
max([len(", ".join(opts)) for (opts, _, _) in args] or (0,))
+ 2,
max([len(", ".join(opts)) for (opts, _) in args] or (0,)) + 2,
)
for task, (_, args) in tasks.items()
)
col_width = max(13, min(30, max_task_len))

tasks_section = ["<h2>CONFIGURED TASKS</h2>"]
for task, (help_text, args_help) in tasks.items():
if task.startswith("_"):
continue
tasks_section.append(
f" <em>{self._padr(task, col_width)}</em> {help_text}"
)
for (options, arg_help_text, default) in args_help:
task_arg_help = [
" ",
f"<em3>{self._padr(', '.join(options), col_width-1)}</em3>",
]
if arg_help_text:
task_arg_help.append(arg_help_text)
if default:
task_arg_help.append(default)
tasks_section.append(" ".join(task_arg_help))

for (options, arg_help_text) in args_help:
tasks_section.append(
" "
f"<em3>{self._padr(', '.join(options), col_width - 2)}</em3>"
f" {arg_help_text}"
)
result.append(tasks_section)

else:
result.append("<h2-dim>NO TASKS CONFIGURED</h2-dim>")

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ poethepoet = "poethepoet.plugin:PoetryPlugin"
help = "Execute poe from this repo (useful for testing)"
script = "poethepoet:main"


[tool.coverage.report]
omit = ["**/site-packages/**", "poethepoet/completion/*", "poethepoet/plugin.py"]

Expand Down
43 changes: 21 additions & 22 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,28 @@ def test_documentation_of_task_named_args(run_poe):
assert (
"\nResult: No task specified.\n" in result.capture
), "Output should include status message"

assert re.search(
r"CONFIGURED TASKS\n"
r" composite_task \s+\n"
r" echo-args \s+\n"
r" static-args-test \s+\n"
r" call_attrs \s+\n"
r" greet \s+\n"
r" print-script-result \s+\n"
r" dont-print-script-result\s+\n"
r" greet-passed-args \s+\n"
r" --greeting \s+\n"
r" --user \s+\n"
r" --optional \s+\n"
r" --upper \s+\n"
r" greet-full-args \s+\n"
r" --greeting, -g \s+\[default: hi\]\n"
r" --user \s+\n"
r" --upper \s+\n"
r" --age, -a \s+\n"
r" --height, -h \s+The user's height in meters\n"
r" greet-strict \s+All arguments are required\n"
r" --greeting \s+this one is required \[default: \$\{DOES\}n't \$\{STUFF\}\]\n"
r" --name \s+and this one is required\n",
r" composite_task \s+\n"
r" echo-args \s+\n"
r" static-args-test \s+\n"
r" call_attrs \s+\n"
r" greet \s+\n"
r" print-script-result \s+\n"
r" dont-print-script-result \s+\n"
r" greet-passed-args \s+\n"
r" --greeting \s+\n"
r" --user \s+\n"
r" --optional \s+\n"
r" --upper \s+\n"
r" greet-full-args \s+\n"
r" --greeting, -g \s+\n"
r" --user \s+\n"
r" --upper \s+\n"
r" --age, -a \s+\n"
r" --height, -h \s+The user's height in meters\n"
r" greet-strict \s+All arguments are required\n"
r" --greeting \s+this one is required\n"
r" --name \s+and this one is required\n",
result.capture,
)

0 comments on commit 506fa9b

Please sign in to comment.