Skip to content

Commit

Permalink
cli: rename cli util, hide data ls from the help (#8321)
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Sep 19, 2022
1 parent b5f20f8 commit 853a918
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions dvc/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
10 changes: 7 additions & 3 deletions dvc/commands/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions dvc/commands/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from dvc.cli.utils import (
append_doc_link,
fix_plumbing_subparsers,
fix_subparsers,
hide_subparsers_from_help,
)
from dvc.commands.experiments import (
apply,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 853a918

Please sign in to comment.