本文整理汇总了Python中argparse._SubParsersAction方法的典型用法代码示例。如果您正苦于以下问题:Python argparse._SubParsersAction方法的具体用法?Python argparse._SubParsersAction怎么用?Python argparse._SubParsersAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类argparse
的用法示例。
在下文中一共展示了argparse._SubParsersAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_connect_subparser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def _build_connect_subparser(
subparser_action: argparse._SubParsersAction,
base_subparser: argparse.ArgumentParser,
) -> None:
"""Returns the subparser for the subcommand `connect`.
Args:
subparser_action (type): Description of parameter `subparser_action`.
base_subparser (type): Description of parameter `base_subparser`.
Returns:
type: Description of returned object.
"""
subparser_action.add_parser(
"connect",
parents=[base_subparser],
help="Connect to Looker instance to test credentials.",
)
示例2: _build_assert_subparser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def _build_assert_subparser(
subparser_action: argparse._SubParsersAction,
base_subparser: argparse.ArgumentParser,
) -> None:
"""Returns the subparser for the subcommand `assert`.
Args:
subparser_action: Description of parameter `subparser_action`.
base_subparser: Description of parameter `base_subparser`.
Returns:
type: Description of returned object.
"""
subparser = subparser_action.add_parser(
"assert", parents=[base_subparser], help="Run Looker data tests."
)
_build_validator_subparser(subparser_action, subparser)
示例3: _build_content_subparser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def _build_content_subparser(
subparser_action: argparse._SubParsersAction,
base_subparser: argparse.ArgumentParser,
) -> None:
subparser = subparser_action.add_parser(
"content", parents=[base_subparser], help="Run Looker content validation."
)
subparser.add_argument(
"--incremental",
action="store_true",
help="Only display errors which are not present on the master branch.",
)
subparser.add_argument(
"--exclude-personal",
action="store_true",
help="Exclude errors found in content in personal folders.",
)
_build_validator_subparser(subparser_action, subparser)
示例4: add_subparser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def add_subparser(self, name: str, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
subparser = parser.add_parser(
name, description="generate report from experiment", help='Generate a report from hyperparameter search experiments.')
subparser.add_argument(
"--log-dir",
required=True,
)
subparser.add_argument(
'--performance-metric',
required=False,
type=str
)
subparser.add_argument(
'--model',
required=False,
type=str
)
subparser.set_defaults(func=generate_report)
return subparser
示例5: parse_args
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def parse_args(self, args=None, namespace=None):
namespace = super(QubesArgumentParser, self).parse_args(args, namespace)
if self._want_app and not self._want_app_no_instance:
self.set_qubes_verbosity(namespace)
namespace.app = qubes.Qubes(namespace.app,
offline_mode=namespace.offline_mode)
if self._want_force_root:
self.dont_run_as_root(namespace)
for action in self._actions:
# pylint: disable=protected-access
if issubclass(action.__class__, QubesAction):
action.parse_qubes_app(self, namespace)
elif issubclass(action.__class__,
argparse._SubParsersAction): # pylint: disable=no-member
assert hasattr(namespace, 'command')
command = namespace.command
subparser = action._name_parser_map[command]
for subaction in subparser._actions:
if issubclass(subaction.__class__, QubesAction):
subaction.parse_qubes_app(self, namespace)
return namespace
示例6: add_subparser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def add_subparser(subparsers: argparse._SubParsersAction,
parents: List[argparse.ArgumentParser]):
show_parser = subparsers.add_parser(
"show",
parents=parents,
conflict_handler="resolve",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
help="Visualize Rasa Stack data")
show_subparsers = show_parser.add_subparsers()
show_stories_subparser = show_subparsers.add_parser(
"stories",
conflict_handler='resolve',
parents=parents,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
help="Show Rasa Core stories")
add_core_visualization_params(show_stories_subparser)
add_config_param(show_stories_subparser)
show_stories_subparser.set_defaults(func=show_stories)
show_parser.set_defaults(func=lambda _: show_parser.print_help(None))
示例7: set_default_subparser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def set_default_subparser(parser,
default_subparser):
"""default subparser selection. Call after setup, just before parse_args()
parser: the name of the parser you're making changes to
default_subparser: the name of the subparser to call by default"""
subparser_found = False
for arg in sys.argv[1:]:
if arg in ['-h', '--help']: # global help if no subparser
break
else:
for x in parser._subparsers._actions:
if not isinstance(x, argparse._SubParsersAction):
continue
for sp_name in x._name_parser_map.keys():
if sp_name in sys.argv[1:]:
subparser_found = True
if not subparser_found:
# insert default in first position before all other arguments
sys.argv.insert(1, default_subparser)
示例8: store_options
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def store_options(self, parser):
"""
Helper method to extract and store all arguments
in a list of all possible arguments.
Used for bash tab completion.
"""
# Run through all parser actions
for action in parser._actions:
for option in action.option_strings:
self.available_options.add(option)
# Get subparsers from parser
subparsers_actions = [
action for action in parser._actions
if isinstance(action, argparse._SubParsersAction)
]
# Run through all subparser actions
for subparsers_action in subparsers_actions:
for choice, subparser in subparsers_action.choices.items():
self.available_options.add(choice)
#
# handlers
#
示例9: _parse_known_args
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def _parse_known_args(self, arg_strings, *args, **kwargs):
in_args = set(arg_strings)
d_sp = self.__default_subparser
if d_sp is not None and not {'-h', '--help'}.intersection(in_args):
for x in self._subparsers._actions:
subparser_found = (
isinstance(x, argparse._SubParsersAction) and
in_args.intersection(x._name_parser_map.keys())
)
if subparser_found:
break
else:
# insert default in first position, this implies no
# global options without a sub_parsers specified
arg_strings = [d_sp] + arg_strings
return super(Parser, self)._parse_known_args(
arg_strings, *args, **kwargs
)
示例10: rev_flags
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def rev_flags(subparsers: argparse._SubParsersAction) -> argparse.ArgumentParser:
rev_parser = subparsers.add_parser(
"rev", help="review a change in the local pull request repository"
)
rev_parser.add_argument(
"-b", "--branch", default="master", help="branch to compare against with"
)
rev_parser.add_argument(
"commit", help="commit/tag/ref/branch in your local git repository"
)
rev_parser.add_argument(
"-r",
"--remote",
default="https://github.com/NixOS/nixpkgs",
help="Name of the nixpkgs repo to review",
)
rev_parser.set_defaults(func=rev_command)
return rev_parser
示例11: wip_flags
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def wip_flags(subparsers: argparse._SubParsersAction) -> argparse.ArgumentParser:
wip_parser = subparsers.add_parser(
"wip", help="review the uncommited changes in the working tree"
)
wip_parser.add_argument(
"-b", "--branch", default="master", help="branch to compare against with"
)
wip_parser.add_argument(
"-s",
"--staged",
action="store_true",
default=False,
help="Whether to build staged changes",
)
wip_parser.add_argument(
"-r",
"--remote",
default="https://github.com/NixOS/nixpkgs",
help="Name of the nixpkgs repo to review",
)
wip_parser.set_defaults(func=wip_command)
return wip_parser
示例12: _delete_parser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def _delete_parser(subparsers: argparse._SubParsersAction) -> None:
d = subparsers.add_parser(
"delete",
help=(
"Consulte metadata (locally or remotely) and delete "
+ "entire pacakge artifacts."
),
)
d.add_argument(
"--dry-run",
action="store_true",
default=False,
help="Do not download or delete files",
)
d.add_argument(
"--workers",
type=int,
default=0,
help="# of parallel iops [Defaults to bandersnatch.conf]",
)
d.add_argument("pypi_packages", nargs="*")
d.set_defaults(op="delete")
示例13: set_default_subparser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def set_default_subparser(self, name, args=None):
"""
see http://stackoverflow.com/questions/5176691/argparse-how-to-specify-a-default-subcommand
"""
subparser_found = False
for arg in sys.argv[1:]:
if arg in ['-h', '--help']: # global help if no subparser
break
else:
for x in self._subparsers._actions:
if not isinstance(x, argparse._SubParsersAction):
continue
for sp_name in x._name_parser_map.keys():
if sp_name in sys.argv[1:]:
subparser_found = True
if not subparser_found:
# insert default in first position, this implies no
# global options without a sub_parsers specified
if args is None:
sys.argv.insert(1, name)
else:
args.insert(0, name)
示例14: get_sub_commands
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def get_sub_commands(parser: argparse.ArgumentParser) -> List[str]:
"""Get a list of subcommands for an ArgumentParser"""
sub_cmds = []
# Check if this is parser has subcommands
if parser is not None and parser._subparsers is not None:
# Find the _SubParsersAction for the subcommands of this parser
for action in parser._subparsers._actions:
if isinstance(action, argparse._SubParsersAction):
for sub_cmd, sub_cmd_parser in action.choices.items():
sub_cmds.append(sub_cmd)
# Look for nested subcommands
for nested_sub_cmd in get_sub_commands(sub_cmd_parser):
sub_cmds.append('{} {}'.format(sub_cmd, nested_sub_cmd))
break
sub_cmds.sort()
return sub_cmds
示例15: get_subparsers
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import _SubParsersAction [as 别名]
def get_subparsers(parser):
"""get_subparser will get a dictionary of subparsers, to help with printing help
"""
actions = [
action
for action in parser._actions
if isinstance(action, argparse._SubParsersAction)
]
subparsers = dict()
for action in actions:
# get all subparsers and print help
for choice, subparser in action.choices.items():
subparsers[choice] = subparser
return subparsers