Skip to content

Commit

Permalink
feat(scripts): hide tasks starting with an underscore from listing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
noirbizarre authored Apr 26, 2023
1 parent 9de7faf commit dde40d0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/docs/usage/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ $ pdm run --list

You can add an `help` option with the description of the script, and it will be displayed in the `Description` column in the above output.

!!! note
Tasks with a name starting with an underscore (`_`) are considered internal (helpers...) and are not shown in the listing.

## Pre & Post Scripts

Like `npm`, PDM also supports tasks composition by pre and post scripts, pre script will be run before the given task and post script will be run after.
Expand Down
1 change: 1 addition & 0 deletions news/1855.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Consider tasks with a name starting by an underscore (`_`) as internal tasks and hide them from the listing.
2 changes: 1 addition & 1 deletion src/pdm/cli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def show_list(self) -> None:
columns = ["Name", "Type", "Description"]
result = []
for name in sorted(self.project.scripts):
if name == "_":
if name.startswith("_"):
continue
task = self.get_task(name)
assert task is not None
Expand Down
11 changes: 11 additions & 0 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ def test_run_show_list_of_scripts(project, invoke):
assert result_lines[4][1:-1].strip() == "test_shell │ shell │ shell command"


def test_run_show_list_of_scripts_hide_internals(project, invoke):
project.pyproject.settings["scripts"] = {
"public": "true",
"_internal": "true",
}
project.pyproject.write()
result = invoke(["run", "--list"], obj=project)
assert "public" in result.output
assert "_internal" not in result.output


def test_run_json_list_of_scripts(project, invoke):
project.pyproject.settings["scripts"] = {
"_": {"env_file": ".env"},
Expand Down

0 comments on commit dde40d0

Please sign in to comment.