Skip to content

Commit

Permalink
stage/exp list: alias --names-only to --name-only
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Apr 21, 2022
1 parent fd440df commit 02b2ab6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions dvc/commands/experiments/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CmdExperimentsList(CmdBase):
def run(self):
names_only = self.args.names_only
name_only = self.args.name_only
exps = self.repo.experiments.ls(
all_commits=self.args.all_commits,
rev=self.args.rev,
Expand All @@ -23,10 +23,10 @@ def run(self):
if branch:
tag = branch.split("/")[-1]
name = tag if tag else baseline[:7]
if not names_only:
if not name_only:
print(f"{name}:")
for exp_name in exps[baseline]:
indent = "" if names_only else "\t"
indent = "" if name_only else "\t"
print(f"{indent}{exp_name}")

return 0
Expand All @@ -45,6 +45,7 @@ def add_parser(experiments_subparsers, parent_parser):
)
add_rev_selection_flags(experiments_list_parser, "List")
experiments_list_parser.add_argument(
"--name-only",
"--names-only",
action="store_true",
help="Only output experiment names (without parent commits).",
Expand Down
5 changes: 2 additions & 3 deletions dvc/commands/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def log_error(relpath: str, exc: Exception):
self.repo.stage_collection_error_handler = log_error

stages = self._get_stages()
names_only = self.args.names_only

data = prepare_stages_data(stages, description=not names_only)
data = prepare_stages_data(stages, description=not self.args.name_only)
ui.table(data.items())

return 0
Expand Down Expand Up @@ -358,6 +356,7 @@ def add_parser(subparsers, parent_parser):
help="List all stages inside the specified directory.",
)
stage_list_parser.add_argument(
"--name-only",
"--names-only",
action="store_true",
default=False,
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/command/test_compat_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def _id_gen(val) -> str:
(["status", "--show-json"], "json"),
(["plots", "show", "--show-json"], "json"),
(["plots", "diff", "--show-json"], "json"),
(["exp", "list", "--names-only"], "name_only"),
(["stage", "list", "--names-only"], "name_only"),
],
ids=_id_gen,
)
def test_backward_compat_flags(args, key):
"""Test support for --show-csv/--show-json/--show-md flags."""
"""Test support for flags kept for backward compatibility."""
cli_args = parse_args(args)
d = vars(cli_args)
assert d[key] is True
2 changes: 1 addition & 1 deletion tests/unit/command/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_experiments_list(dvc, scm, mocker):
"-1",
"--rev",
"foo",
"--names-only",
"--name-only",
]
)
assert cli_args.func == CmdExperimentsList
Expand Down

0 comments on commit 02b2ab6

Please sign in to comment.