Skip to content

Commit

Permalink
Note when commands & tasks accept extra args.
Browse files Browse the repository at this point in the history
This completes the `-l` / `--list` output needed to allow command-line
exploration of a project's dev setup.
  • Loading branch information
jsirois committed Jan 30, 2025
1 parent 0dd29c0 commit 2a02ec0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## 0.16.0

Note when commands and tasks can accept extra args in `-l` / `--list` output.

## 0.15.0

Add support for hiding commands and tasks from `-l` / `--list` output.
Expand Down
2 changes: 1 addition & 1 deletion dev_cmd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 John Sirois.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

__version__ = "0.15.0"
__version__ = "0.16.0"
2 changes: 1 addition & 1 deletion dev_cmd/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Task:
hidden: bool = False
description: str | None = None

def accepts_extra_args(self, skips: Container[str]) -> Command | None:
def accepts_extra_args(self, skips: Container[str] = ()) -> Command | None:
if self.name in skips:
return None
return self.steps.accepts_extra_args(skips)
Expand Down
14 changes: 12 additions & 2 deletions dev_cmd/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,14 @@ def _list(
if command.hidden:
continue
rendered_command_name = color.color(command.name, fg="magenta", style="bold")
if command.accepts_extra_args:
extra_args_help = color.magenta(f" (-- extra {command.args[0]} args ...)")
rendered_command_name = f"{rendered_command_name}{extra_args_help}"
if command.description:
console.print(f"{rendered_command_name}: {color.color(command.description, fg='gray')}")
console.print(f"{rendered_command_name}:")
console.print(f" {color.color(command.description, fg='gray')}")
elif command.factor_descriptions:
console.print(f"{rendered_command_name}:")
else:
console.print(rendered_command_name)
for factor_description in command.factor_descriptions:
Expand Down Expand Up @@ -318,8 +324,12 @@ def _list(
if task.hidden:
continue
rendered_task_name = color.color(task.name, fg="magenta", style="bold")
if extra_args_cmd := task.accepts_extra_args():
extra_args_help = color.magenta(f" (-- extra {extra_args_cmd.args[0]} args ...)")
rendered_task_name = f"{rendered_task_name}{extra_args_help}"
if task.description:
console.print(f"{rendered_task_name}: {color.color(task.description, fg='gray')}")
console.print(f"{rendered_task_name}: ")
console.print(f" {color.color(task.description, fg='gray')}")
else:
console.print(rendered_task_name)

Expand Down

0 comments on commit 2a02ec0

Please sign in to comment.