def __call__(self, parser, namespace, values, option_string=None): """Render a help document according to the style in values. Args: parser: The ArgParse object. namespace: The ArgParse namespace. values: The --document flag ArgDict() value: style=STYLE The output style. Must be specified. title=DOCUMENT TITLE The document title. notes=SENTENCES Inserts SENTENCES into the document NOTES section. option_string: The ArgParse flag string. Raises: parser_errors.ArgumentError: For unknown flag value attribute name. """ base.LogCommand(parser.prog, namespace) if default_style: # --help metrics.Loaded() style = default_style notes = None title = None for attributes in values: for name, value in six.iteritems(attributes): if name == 'notes': notes = value elif name == 'style': style = value elif name == 'title': title = value else: raise parser_errors.ArgumentError( 'Unknown document attribute [{0}]'.format(name)) if title is None: title = command.dotted_name metrics.Help(command.dotted_name, style) # '--help' is set by the --help flag, the others by gcloud <style> ... . if style in ('--help', 'help', 'topic'): style = 'text' md = io.StringIO(markdown.Markdown(command)) out = (io.StringIO() if console_io.IsInteractive(output=True) else None) if style == 'linter': meta_data = GetCommandMetaData(command) else: meta_data = None render_document.RenderDocument(style, md, out=out or log.out, notes=notes, title=title, command_metadata=meta_data) metrics.Ran() if out: console_io.More(out.getvalue()) sys.exit(0)
def Run(self, cli, args): """Run this command with the given arguments. Args: cli: The cli.CLI object for this command line tool. args: The arguments for this command as a namespace. Returns: The object returned by the module's Run() function. Raises: exceptions.Error: if thrown by the Run() function. exceptions.ExitCodeNoError: if the command is returning with a non-zero exit code. """ metrics.Loaded() tool_context = {} if self._parent_group: self._parent_group.RunGroupFilter(tool_context, args) command_instance = self._common_type(cli=cli, context=tool_context) base.LogCommand(self.dotted_name, args) resources = command_instance.Run(args) resources = display.Displayer(command_instance, args, resources, display_info=self.ai.display_info).Display() metrics.Ran() if command_instance.exit_code != 0: raise exceptions.ExitCodeNoError(exit_code=command_instance.exit_code) return resources
def __call__(self, parser, namespace, values, option_string=None): """Render a help document according to the style in values. Args: parser: The ArgParse object. namespace: The ArgParse namespace. values: The --document flag ArgDict() value: style=STYLE The output style. Must be specified. title=DOCUMENT TITLE The document title. notes=SENTENCES Inserts SENTENCES into the document NOTES section. option_string: The ArgParse flag string. Raises: ArgumentTypeError: For unknown flag value attribute name. """ if default_style: # --help metrics.Loaded() style = default_style notes = None title = None for attributes in values: for name, value in attributes.iteritems(): if name == 'notes': notes = value elif name == 'style': style = value elif name == 'title': title = value else: raise argparse.ArgumentTypeError( 'Unknown document attribute [{}]'.format(name)) if title is None: title = command.dotted_name metrics.Help(command.dotted_name, style) # 'help' is set by the help command, '--help' by the --help flag. if style in ('--help', 'help'): style = 'text' md = cStringIO.StringIO(markdown.Markdown(command)) out = (cStringIO.StringIO() if console_io.IsInteractive( output=True) else None) render_document.RenderDocument(style, md, out=out, notes=notes, title=title) metrics.Ran() if out: console_io.More(out.getvalue()) sys.exit(0)
def Run(self, cli, args): """Run this command with the given arguments. Args: cli: The cli.CLI object for this command line tool. args: The arguments for this command as a namespace. Returns: The object returned by the module's Run() function. Raises: exceptions.Error: if thrown by the Run() function. exceptions.ExitCodeNoError: if the command is returning with a non-zero exit code. """ def Http(**kwargs): # Possibly override timeout, making sure to leave kwargs[timeout] # undefined (as opposed to None) if args.http_timout is not set. if args.http_timeout: kwargs['timeout'] = args.http_timeout return core_cli.Http(cmd_path=self.dotted_name, trace_token=args.trace_token, log_http=properties.VALUES.core.log_http.GetBool(), **kwargs) tool_context = self._config_hooks.load_context() last_group = None for context_filter in self._config_hooks.context_filters: last_group = context_filter(tool_context, Http, args) command_instance = self._common_type( cli=cli, context=tool_context, group=last_group, http_func=Http, format_string=args.format or 'yaml') if args.format: output_formatter = command_instance.format else: output_formatter = lambda obj: command_instance.Display(args, obj) log.debug('Running %s with %s.', self.dotted_name, args) metrics.Loaded() result = command_instance.Run(args) if log.IsUserOutputEnabled(): output_formatter(result) metrics.Ran() if command_instance.exit_code != 0: raise exceptions.ExitCodeNoError(exit_code=command_instance.exit_code) return result
def Run(self, cli, args): """Run this command with the given arguments. Args: cli: The cli.CLI object for this command line tool. args: The arguments for this command as a namespace. Returns: The object returned by the module's Run() function. Raises: exceptions.Error: if thrown by the Run() function. """ def Http(**kwargs): return core_cli.Http(cmd_path=self.dotted_name, trace_token=args.trace_token, log_http=args.log_http, timeout=args.http_timeout, **kwargs) tool_context = self._config_hooks.load_context() last_group = None for context_filter in self._config_hooks.context_filters: last_group = context_filter(tool_context, Http, args) command_instance = self._common_type(cli=cli, context=tool_context, group=last_group, http_func=Http, format_string=args.format or 'yaml') if args.format: output_formatter = command_instance.format else: output_formatter = lambda obj: command_instance.Display(args, obj) log.debug('Running %s with %s.', self.dotted_name, args) metrics.Loaded() result = command_instance.Run(args) if log.IsUserOutputEnabled(): output_formatter(result) metrics.Ran() if command_instance.exit_code != 0: raise exceptions.ExitCodeNoError( exit_code=command_instance.exit_code) return result
def Run(self, cli, args): """Run this command with the given arguments. Args: cli: The cli.CLI object for this command line tool. args: The arguments for this command as a namespace. Returns: The object returned by the module's Run() function. Raises: exceptions.Error: if thrown by the Run() function. exceptions.ExitCodeNoError: if the command is returning with a non-zero exit code. """ metrics.Loaded() tool_context = {} if self._parent_group: self._parent_group.RunGroupFilter(tool_context, args) command_instance = self._common_type(cli=cli, context=tool_context) log.debug(u'Running [{cmd}] with arguments: [{args}]'.format( cmd=self.dotted_name, args=u', '.join(u'{arg}: "{value}"'.format(arg=arg, value=value) for arg, value in sorted( args.GetSpecifiedArgs().iteritems())))) resources = command_instance.Run(args) resources = display.Displayer( command_instance, args, resources, display_info=self.ai.display_info).Display() metrics.Ran() if command_instance.exit_code != 0: raise exceptions.ExitCodeNoError( exit_code=command_instance.exit_code) return resources
def __call__(self, parser, namespace, values, option_string=None): metrics.Loaded() func() sys.exit(0)
def __call__(self, parser, namespace, values, option_string=None): base.LogCommand(parser.prog, namespace) metrics.Loaded() func() sys.exit(0)