本文整理匯總了Python中argparse.ZERO_OR_MORE屬性的典型用法代碼示例。如果您正苦於以下問題:Python argparse.ZERO_OR_MORE屬性的具體用法?Python argparse.ZERO_OR_MORE怎麽用?Python argparse.ZERO_OR_MORE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類argparse
的用法示例。
在下文中一共展示了argparse.ZERO_OR_MORE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init_parser
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def init_parser(self):
"""
Init command line parser
:return:
"""
parser = argparse.ArgumentParser(description='ROCA TLS Fingerprinter')
parser.add_argument('--debug', dest='debug', default=False, action='store_const', const=True,
help='Debugging logging')
parser.add_argument('--dump', dest='dump', default=False, action='store_const', const=True,
help='Dump all processed info')
parser.add_argument('--flatten', dest='flatten', default=False, action='store_const', const=True,
help='Flatten the dump')
parser.add_argument('--indent', dest='indent', default=False, action='store_const', const=True,
help='Indent the dump')
parser.add_argument('--hosts', dest='hosts', default=False, action='store_const', const=True,
help='Arguments are host names not file names')
parser.add_argument('files', nargs=argparse.ZERO_OR_MORE, default=[],
help='files to process')
return parser
示例2: __init__
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def __init__(self, option_strings, nargs=1, dest='vmnames', help=None,
**kwargs):
if help is None:
if nargs == argparse.OPTIONAL:
help = 'at most one domain name'
elif nargs == 1:
help = 'a domain name'
elif nargs == argparse.ZERO_OR_MORE:
help = 'zero or more domain names'
elif nargs == argparse.ONE_OR_MORE:
help = 'one or more domain names'
elif nargs > 1:
help = '%s domain names' % nargs
else:
raise argparse.ArgumentError(
nargs, "Passed unexpected value {!s} as {!s} nargs ".format(
nargs, dest))
super(VmNameAction, self).__init__(option_strings, dest=dest, help=help,
nargs=nargs, **kwargs)
示例3: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
"""Place default value in help string."""
h = action.help
if '%(default)' not in action.help:
if action.default != '' and action.default != [] and \
action.default is not None and \
not isinstance(type(action.default), bool):
if action.default is not argparse.SUPPRESS:
defaulting_nargs = [
argparse.OPTIONAL, argparse.ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
if '\n' in h:
lines = h.splitlines()
lines[0] += ' (default: %(default)s)'
h = '\n'.join(lines)
else:
h += ' (default: %(default)s)'
return h
示例4: test_apcustom_narg_tuple_zero_base
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def test_apcustom_narg_tuple_zero_base():
parser = Cmd2ArgumentParser()
arg = parser.add_argument('arg', nargs=(0,))
assert arg.nargs == argparse.ZERO_OR_MORE
assert arg.nargs_range is None
assert "[arg [...]]" in parser.format_help()
parser = Cmd2ArgumentParser()
arg = parser.add_argument('arg', nargs=(0, 1))
assert arg.nargs == argparse.OPTIONAL
assert arg.nargs_range is None
assert "[arg]" in parser.format_help()
parser = Cmd2ArgumentParser()
arg = parser.add_argument('arg', nargs=(0, 3))
assert arg.nargs == argparse.ZERO_OR_MORE
assert arg.nargs_range == (0, 3)
assert "arg{0..3}" in parser.format_help()
# noinspection PyUnresolvedReferences
示例5: _format_args
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _format_args(self, action, default_metavar) -> str:
get_metavar = self._metavar_formatter(action, default_metavar)
# Begin cmd2 customization (less verbose)
nargs_range = getattr(action, ATTR_NARGS_RANGE, None)
if nargs_range is not None:
if nargs_range[1] == constants.INFINITY:
range_str = '{}+'.format(nargs_range[0])
else:
range_str = '{}..{}'.format(nargs_range[0], nargs_range[1])
result = '{}{{{}}}'.format('%s' % get_metavar(1), range_str)
elif action.nargs == ZERO_OR_MORE:
result = '[%s [...]]' % get_metavar(1)
elif action.nargs == ONE_OR_MORE:
result = '%s [...]' % get_metavar(1)
elif isinstance(action.nargs, int) and action.nargs > 1:
result = '{}{{{}}}'.format('%s' % get_metavar(1), action.nargs)
# End cmd2 customization
else:
result = super()._format_args(action, default_metavar)
return result
# noinspection PyCompatibility
示例6: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
"""Place default value in help string."""
h = action.help
if '%(default)' not in action.help:
if action.default != '' and action.default != [] and action.default is not None and type(action.default) != bool:
if action.default is not argparse.SUPPRESS:
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
if '\n' in h:
lines = h.splitlines()
lines[0] += ' (default: %(default)s)'
h = '\n'.join(lines)
else:
h += ' (default: %(default)s)'
return h
示例7: prepare_playbook_plugin
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def prepare_playbook_plugin():
@configure
def main():
parser = argparse.ArgumentParser(
description="Prepare playbook plugins"
)
parser.add_argument(
"plugin_name",
nargs=argparse.ZERO_OR_MORE,
default=[],
help="Namespace of plugin to prepare. Empty means all plugins"
)
args = parser.parse_args()
plugs = plugins.get_playbook_plugins()
if args.plugin_name:
plugs = {k: v for k, v in plugs.items() if k in args.plugin_name}
plugs = {k: v() for k, v in plugs.items()}
for name, plug in sorted(plugs.items()):
LOG.info("Prepare plugin %s", name)
plug.prepare_plugin()
return main()
示例8: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
help = action.help
if not action.default:
return help
if '%(default)' not in action.help:
if action.default is not argparse.SUPPRESS:
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
help += ' (default: %(default)s)'
return help
示例9: _format_args
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _format_args(self, action, default_metavar) -> str:
get_metavar = self._metavar_formatter(action, default_metavar)
# Begin cmd2 customization (less verbose)
if isinstance(action, _RangeAction) and \
action.nargs_min is not None and action.nargs_max is not None:
result = '{}{{{}..{}}}'.format('%s' % get_metavar(1), action.nargs_min, action.nargs_max)
elif action.nargs == ZERO_OR_MORE:
result = '[%s [...]]' % get_metavar(1)
elif action.nargs == ONE_OR_MORE:
result = '%s [...]' % get_metavar(1)
# End cmd2 customization
else:
result = super()._format_args(action, default_metavar)
return result
示例10: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
help = action.help
if '%(default)' not in action.help:
if action.default is not argparse.SUPPRESS:
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
help += ' (default: %(default)s)'
if (
hasattr(action, 'recommended')
and action.recommended
and action.recommended != action.default
):
help += '(recommended: %(recommended)s)'
help = help.replace(')(recommended', ', recommended')
return help
示例11: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
help_text = action.help
if '%(default)' not in action.help and action.default is not argparse.SUPPRESS:
if action.option_strings or action.nargs in [argparse.OPTIONAL, argparse.ZERO_OR_MORE]:
if (
(not isinstance(action.default, bool) and isinstance(action.default, int))
or (isinstance(action.default, str) and action.default)
):
help_text += ' (default: %(default)s)'
return help_text
示例12: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
self.default = None
if action.default not in (None, argparse.SUPPRESS):
if action.option_strings or action.nargs in (argparse.OPTIONAL, argparse.ZERO_OR_MORE):
self.default = self.__format_map.get(action.dest, lambda s: s)(action.default)
return action.help
示例13: __init__
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def __init__(self, arg_action: argparse.Action) -> None:
self.action = arg_action
self.min = None
self.max = None
self.count = 0
self.is_remainder = (self.action.nargs == argparse.REMAINDER)
# Check if nargs is a range
nargs_range = getattr(self.action, ATTR_NARGS_RANGE, None)
if nargs_range is not None:
self.min = nargs_range[0]
self.max = nargs_range[1]
# Otherwise check against argparse types
elif self.action.nargs is None:
self.min = 1
self.max = 1
elif self.action.nargs == argparse.OPTIONAL:
self.min = 0
self.max = 1
elif self.action.nargs == argparse.ZERO_OR_MORE or self.action.nargs == argparse.REMAINDER:
self.min = 0
self.max = constants.INFINITY
elif self.action.nargs == argparse.ONE_OR_MORE:
self.min = 1
self.max = constants.INFINITY
else:
self.min = self.action.nargs
self.max = self.action.nargs
# noinspection PyProtectedMember
示例14: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
"""
Appends the default argument value to the help string for non-required args that have default values.
This implementation is loosely based off of the argparse.ArgumentDefaultsHelpFormatter.
"""
help_string = action.help
if not action.required:
if action.default not in (argparse.SUPPRESS, None):
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
# using old string formatting style here because argparse internals use that
help_string += ' (default: %(default)s)'
return help_string
示例15: _get_help_string
# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ZERO_OR_MORE [as 別名]
def _get_help_string(self, action):
'''
This module was taken from the RawDescriptionHelpFormatter class
within argparse. It deals with the formatting of the description string
and allows properly formatted descriptions ot be printed without line
wrapping.
'''
help = action.help
if '%(default)' not in action.help:
if action.default is not argparse.SUPPRESS:
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
help += ' (default: %(default)s)'
return help