Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
arg_strings = [formatting.Underline(arg.upper())
for arg in args_with_no_defaults]
else:
arg_strings = [
'--{arg}={arg_upper}'.format(
arg=arg, arg_upper=formatting.Underline(arg.upper()))
for arg in args_with_no_defaults]
arg_and_flag_strings.extend(arg_strings)
# If there are any arguments that are treated as flags:
if args_with_defaults or spec.kwonlyargs or spec.varkw:
arg_and_flag_strings.append('')
if spec.varargs:
varargs_string = '[{varargs}]...'.format(
varargs=formatting.Underline(spec.varargs.upper()))
arg_and_flag_strings.append(varargs_string)
return ' '.join(arg_and_flag_strings)
Args:
flag: The name of the flag.
docstring_info: A docstrings.DocstringInfo namedtuple with information about
the containing function's docstring.
required: Whether the flag is required. Keyword-only arguments (only in
Python 3) become required flags, whereas normal keyword arguments become
optional flags.
Returns:
A string to be used in constructing the help screen for the function.
"""
description = _GetArgDescription(flag, docstring_info)
flag_string_template = '--{flag_name}={flag_name_upper}'
flag = flag_string_template.format(
flag_name=flag,
flag_name_upper=formatting.Underline(flag.upper()))
if required:
flag += ' (required)'
return _CreateItem(flag, description, indent=4)
metadata: Metadata for the component, including whether it accepts
positional arguments.
Returns:
The constructed args and flags string.
"""
args_with_no_defaults = spec.args[:len(spec.args) - len(spec.defaults)]
args_with_defaults = spec.args[len(spec.args) - len(spec.defaults):]
# Check if positional args are allowed. If not, require flag syntax for args.
accepts_positional_args = metadata.get(decorators.ACCEPTS_POSITIONAL_ARGS)
arg_and_flag_strings = []
if args_with_no_defaults:
if accepts_positional_args:
arg_strings = [formatting.Underline(arg.upper())
for arg in args_with_no_defaults]
else:
arg_strings = [
'--{arg}={arg_upper}'.format(
arg=arg, arg_upper=formatting.Underline(arg.upper()))
for arg in args_with_no_defaults]
arg_and_flag_strings.extend(arg_strings)
# If there are any arguments that are treated as flags:
if args_with_defaults or spec.kwonlyargs or spec.varkw:
arg_and_flag_strings.append('')
if spec.varargs:
varargs_string = '[{varargs}]...'.format(
varargs=formatting.Underline(spec.varargs.upper()))
arg_and_flag_strings.append(varargs_string)
def _CreateAvailabilityLine(header, items,
header_indent=2, items_indent=25,
line_length=LINE_LENGTH):
items_width = line_length - items_indent
items_text = '\n'.join(formatting.WrappedJoin(items, width=items_width))
indented_items_text = formatting.Indent(items_text, spaces=items_indent)
indented_header = formatting.Indent(header, spaces=header_indent)
return indented_header + indented_items_text[len(indented_header):] + '\n'
output = []
show_help = False
for help_flag in ('-h', '--help'):
if help_flag in component_trace.elements[-1].args:
show_help = True
if show_help:
command = '{cmd} -- --help'.format(cmd=component_trace.GetCommand())
print('INFO: Showing help with the command {cmd}.\n'.format(
cmd=pipes.quote(command)), file=sys.stderr)
help_text = helptext.HelpText(result, trace=component_trace,
verbose=component_trace.verbose)
output.append(help_text)
Display(output, out=sys.stderr)
else:
print(formatting.Error('ERROR: ')
+ component_trace.elements[-1].ErrorAsStr(),
file=sys.stderr)
error_text = helptext.UsageText(result, trace=component_trace,
verbose=component_trace.verbose)
print(error_text, file=sys.stderr)
def _CreateAvailabilityLine(header, items,
header_indent=2, items_indent=25,
line_length=LINE_LENGTH):
items_width = line_length - items_indent
items_text = '\n'.join(formatting.WrappedJoin(items, width=items_width))
indented_items_text = formatting.Indent(items_text, spaces=items_indent)
indented_header = formatting.Indent(header, spaces=header_indent)
return indented_header + indented_items_text[len(indented_header):] + '\n'
def _CreateArgItem(arg, docstring_info):
"""Returns a string describing a positional argument.
Args:
arg: The name of the positional argument.
docstring_info: A docstrings.DocstringInfo namedtuple with information about
the containing function's docstring.
Returns:
A string to be used in constructing the help screen for the function.
"""
description = _GetArgDescription(arg, docstring_info)
arg = arg.upper()
return _CreateItem(formatting.BoldUnderline(arg), description, indent=4)
def _CreateOutputSection(name, content):
return """{name}
{content}""".format(name=formatting.Bold(name),
content=formatting.Indent(content, 4))