コード例 #1
0
ファイル: backend.py プロジェクト: dovikn/glass-findmycar
    def AddSubGroup(self, group):
        """Merges another command group under this one.

    If we load command groups for alternate locations, this method is used to
    make those extra sub groups fall under this main group in the CLI.

    Args:
      group: Any other CommandGroup object that should be added to the CLI
    """
        self.groups.append(group)
        self.all_sub_names.add(group.name)
        self._parser.usage = usage_text.GenerateUsage(self, self._ai)
コード例 #2
0
ファイル: backend.py プロジェクト: dovikn/glass-findmycar
    def __init__(self,
                 module_dir,
                 module_path,
                 path,
                 construction_id,
                 parser_group,
                 config_hooks,
                 help_func,
                 parent_group=None):
        """Create a new command group.

    Args:
      module_dir: always the root of the whole command tree
      module_path: a list of command group names that brought us down to this
          command group from the top module directory
      path: similar to module_path, but is the path to this command group
          with respect to the CLI itself.  This path should be used for things
          like error reporting when a specific element in the tree needs to be
          referenced
      construction_id: str, A unique identifier for the CLILoader that is
          being constructed.
      parser_group: the current argparse parser, or None if this is the root
          command group.  The root command group will allocate the initial
          top level argparse parser.
      config_hooks: a ConfigHooks object to use for loading context
      help_func: func([command path]), A function to call with --help.
      parent_group: CommandGroup, The parent of this group. None if at the
          root.

    Raises:
      LayoutException: if the module has no sub groups or commands
    """

        super(CommandGroup, self).__init__(module_dir=module_dir,
                                           module_path=module_path,
                                           path=path,
                                           construction_id=construction_id,
                                           config_hooks=config_hooks,
                                           help_func=help_func,
                                           allow_positional_args=False,
                                           parser_group=parser_group,
                                           parent_group=parent_group)

        self._module_dir = module_dir

        self._LoadSubGroups()

        self._parser.usage = usage_text.GenerateUsage(self, self._ai)
        self._parser.error = usage_text.PrintShortHelpError(self._parser, self)
コード例 #3
0
ファイル: backend.py プロジェクト: dovikn/glass-findmycar
    def __init__(self,
                 module_dir,
                 module_path,
                 path,
                 construction_id,
                 config_hooks,
                 parser_group,
                 help_func,
                 parent_group=None):
        """Create a new command.

    Args:
      module_dir: str, The root of the command tree.
      module_path: a list of command group names that brought us down to this
          command from the top module directory
      path: similar to module_path, but is the path to this command with respect
          to the CLI itself.  This path should be used for things like error
          reporting when a specific element in the tree needs to be referenced
      construction_id: str, A unique identifier for the CLILoader that is
          being constructed.
      config_hooks: a ConfigHooks object to use for loading context
      parser_group: argparse.Parser, The parser to be used for this command.
      help_func: func([str]), Detailed help function.
      parent_group: CommandGroup, The parent of this command.
    """
        super(Command, self).__init__(module_dir=module_dir,
                                      module_path=module_path,
                                      path=path,
                                      construction_id=construction_id,
                                      config_hooks=config_hooks,
                                      help_func=help_func,
                                      allow_positional_args=True,
                                      parser_group=parser_group,
                                      parent_group=parent_group)

        self._parser.set_defaults(cmd_func=self.Run,
                                  command_path=self._path,
                                  err_func=usage_text.PrintShortHelpError(
                                      self._parser, self))

        self._parser.usage = usage_text.GenerateUsage(self, self._ai)
コード例 #4
0
  def error(self, message):
    """Override's argparse.ArgumentParser's .error(message) method.

    Specifically, it avoids reprinting the program name and the string "error:".

    Args:
      message: str, The error message to print.
    """
    if self._is_group:
      shorthelp = usage_text.ShortHelpText(
          self._calliope_command, self._calliope_command.ai)
      # pylint:disable=protected-access
      argparse._sys.stderr.write(shorthelp + '\n')
    else:
      self.usage = usage_text.GenerateUsage(
          self._calliope_command, self._calliope_command.ai)
      # pylint:disable=protected-access
      self.print_usage(argparse._sys.stderr)

    log.error('({prog}) {message}'.format(prog=self.prog, message=message))
    self.exit(2)