From 853a918d5cf535deefd4967dd8780289ec25dddd Mon Sep 17 00:00:00 2001 From: skshetry Date: Mon, 19 Sep 2022 10:29:52 +0545 Subject: [PATCH] cli: rename cli util, hide `data ls` from the help (#8321) --- dvc/cli/utils.py | 7 +++++-- dvc/commands/data.py | 10 +++++++--- dvc/commands/experiments/__init__.py | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dvc/cli/utils.py b/dvc/cli/utils.py index 5b47b9d27..537d6d11e 100644 --- a/dvc/cli/utils.py +++ b/dvc/cli/utils.py @@ -21,10 +21,13 @@ def append_doc_link(help_message, path): ) -def fix_plumbing_subparsers(subparsers): - # metavar needs to be explicitly set in order to hide plumbing subcommands +def hide_subparsers_from_help(subparsers): + # metavar needs to be explicitly set in order to hide subcommands # from the 'positional arguments' choices list # see: https://bugs.python.org/issue22848 + # Need to set `add_help=False`, but avoid setting `help` + # (not even to `argparse.SUPPPRESS`). + # NOTE: The argument is the parent subparser, not the subcommand parser. cmds = [ cmd for cmd, parser in subparsers.choices.items() if parser.add_help ] diff --git a/dvc/commands/data.py b/dvc/commands/data.py index 1fae632fb..4fdb59d67 100644 --- a/dvc/commands/data.py +++ b/dvc/commands/data.py @@ -8,7 +8,11 @@ from funcy import chunks, compact, log_durations from dvc.cli import completion from dvc.cli.actions import CommaSeparatedArgs from dvc.cli.command import CmdBase -from dvc.cli.utils import append_doc_link, fix_subparsers +from dvc.cli.utils import ( + append_doc_link, + fix_subparsers, + hide_subparsers_from_help, +) from dvc.ui import ui from dvc.utils import colorize @@ -251,7 +255,7 @@ def add_parser(subparsers, parent_parser): parents=[parent_parser], description=append_doc_link(DATA_LS_HELP, "data/ls"), formatter_class=argparse.RawDescriptionHelpFormatter, - help=DATA_LS_HELP, + add_help=False, ) data_ls_parser.add_argument( "--md", @@ -289,5 +293,5 @@ def add_parser(subparsers, parent_parser): ".dvc files, or stage names." ), ).complete = completion.DVCFILES_AND_STAGE - data_ls_parser.set_defaults(func=CmdDataLs) + hide_subparsers_from_help(data_subparsers) diff --git a/dvc/commands/experiments/__init__.py b/dvc/commands/experiments/__init__.py index 76fed59ec..addf85b7d 100644 --- a/dvc/commands/experiments/__init__.py +++ b/dvc/commands/experiments/__init__.py @@ -2,8 +2,8 @@ import argparse from dvc.cli.utils import ( append_doc_link, - fix_plumbing_subparsers, fix_subparsers, + hide_subparsers_from_help, ) from dvc.commands.experiments import ( apply, @@ -59,7 +59,7 @@ def add_parser(subparsers, parent_parser): fix_subparsers(experiments_subparsers) for cmd in SUB_COMMANDS: cmd.add_parser(experiments_subparsers, parent_parser) - fix_plumbing_subparsers(experiments_subparsers) + hide_subparsers_from_help(experiments_subparsers) def add_rev_selection_flags(