Exemplo n.º 1
0
    def _format_commands(self,
                         formatter: argparse.HelpFormatter,
                         command: Command = None) -> None:
        prefix = self.prefixes['commands']
        if command:
            if command.group:
                prefix = self.prefixes['group']
            elif command.guesses:
                prefix = self.prefixes['guesses']

        formatter.start_section(Fore.YELLOW + prefix + Fore.RESET)
        prev_group = ''
        colors = {True: Fore.GREEN, False: Fore.BLUE}
        color = True
        for name, handler in self._handlers.items():
            if command and command.guesses and name not in command.guesses:
                continue
            # switch colors for every group
            group, _, subname = name.rpartition(' ')
            if group != prev_group:
                prev_group = group
                color = not color

            formatter.add_argument(
                argparse.Action(
                    option_strings=[colors[color] + name + Fore.RESET],
                    dest='',
                    help=handler.summary,
                ))
        formatter.end_section()
Exemplo n.º 2
0
 def __call__(self, *a, **kw):
     actions = [
         Action([i], help=getattr(pathmaker, i).__doc__, dest='')
         for i in sorted(pathmaker.__all__)
         if not i.startswith('_') and callable(getattr(pathmaker, i))
     ]
     formatter = HelpFormatter('')
     formatter.add_text(
         "An explicit layout strategy can be specified.  This is to "
         "instruct how ExplosiveFUSE should present file entries across "
         "all archive files within its mount point.  Do note that "
         "the final outcome of the layout is also influenced by the usage "
         "of the '--overwrite' and the '--omit-arcname' flags, and "
         "arguments which may associate with each of the strategies. "
         "They are specified by appending ':', followed by the value of "
         "each positional argument(s).")
     formatter.start_section('Available layout strategies')
     formatter.add_arguments(actions)
     formatter.end_section()
     print(formatter.format_help())
     sys.exit(0)
Exemplo n.º 3
0
 def __call__(self, *a, **kw):
     actions = [
         Action([i], help=getattr(pathmaker, i).__doc__, dest='')
         for i in sorted(pathmaker.__all__)
         if not i.startswith('_') and callable(getattr(pathmaker, i))
     ]
     formatter = HelpFormatter('')
     formatter.add_text(
         "An explicit layout strategy can be specified.  This is to "
         "instruct how ExplosiveFUSE should present file entries across "
         "all archive files within its mount point.  Do note that "
         "the final outcome of the layout is also influenced by the usage "
         "of the '--overwrite' and the '--omit-arcname' flags, and "
         "arguments which may associate with each of the strategies. "
         "They are specified by appending ':', followed by the value of "
         "each positional argument(s)."
     )
     formatter.start_section('Available layout strategies')
     formatter.add_arguments(actions)
     formatter.end_section()
     print(formatter.format_help())
     sys.exit(0)
Exemplo n.º 4
0
def get_help(parser):
    """
    Return help text for the parser.

    :param parser: parser
    :type parser: ArgumentParser
    :return: fully formatted help string
    :rtype: str
    """
    # Code almost identical with parser.print_help() with next changes:
    # it return text instead print
    # it place group 'command arguments' to the first place
    width = min(get_terminal_width(), 100)
    formatter = HelpFormatter(prog=parser.prog,
                              max_help_position=30,
                              width=width)
    # usage
    formatter.add_usage(parser.usage, parser._actions,
                        parser._mutually_exclusive_groups)
    # description
    formatter.add_text(parser.description)

    # positionals, optionals and user-defined groups
    groups = list(parser._action_groups)
    groups.sort(key=lambda x: x.title != 'command arguments')
    for action_group in groups:
        formatter.start_section(action_group.title)
        formatter.add_text(action_group.description)
        formatter.add_arguments(action_group._group_actions)
        formatter.end_section()

    # epilog
    formatter.add_text(parser.epilog)

    # determine help from format above
    return formatter.format_help()