コード例 #1
0
    def _render_sub_command_arguments(
            self, layout,
            arguments):  # type: (BlockLayout, Iterable[Argument]) -> None
        for argument in arguments:
            self._render_argument(layout, argument)

        layout.add(EmptyLine())
コード例 #2
0
    def _render_sub_command_options(
            self, layout,
            options):  # type: (BlockLayout, Iterable[Option]) -> None
        for option in options:
            self._render_option(layout, option)

        layout.add(EmptyLine())
コード例 #3
0
    def _render_sub_command(self, layout,
                            command):  # type: (BlockLayout, Command) -> None
        config = command.config
        if config.is_hidden():
            return

        description = config.description
        help = config.help
        arguments = command.args_format.get_arguments(False)
        options = command.args_format.get_options(False)

        # TODO: option commands
        name = "<u>{}</u>".format(command.name)

        layout.add(Paragraph(name))

        with layout.block():
            if description:
                self._render_sub_command_description(layout, description)

            if help:
                self._render_sub_command_help(layout, help)

            if arguments:
                self._render_sub_command_arguments(layout, arguments.values())

            if options:
                self._render_sub_command_options(layout, options.values())

            if not description and not help and not arguments and not options:
                layout.add(EmptyLine())
コード例 #4
0
    def _render_commands(
            self, layout,
            commands):  # type: (BlockLayout, CommandCollection) -> None
        layout.add(Paragraph("<b>AVAILABLE COMMANDS</b>"))

        with layout.block():
            for command in sorted(commands, key=lambda c: c.name):
                self._render_command(layout, command)

        layout.add(EmptyLine())
コード例 #5
0
    def _render_usage(self, layout,
                      command):  # type: (BlockLayout, Command) -> None
        formats_to_print = []

        # Start with the default commands
        if command.has_default_sub_commands():
            # If the command has default commands, print them
            for sub_command in command.default_sub_commands:
                # The name of the sub command is only optional (i.e. printed
                # wrapped in brackets: "[sub]") if the command is not
                # anonymous
                name_optional = not sub_command.config.is_anonymous()

                formats_to_print.append(
                    (sub_command.args_format, name_optional))
        else:
            # Otherwise print the command's usage itself
            formats_to_print.append((command.args_format, False))

        # Add remaining sub-commands
        for sub_command in command.sub_commands:
            if sub_command.config.is_hidden():
                continue

            # Don't duplicate default commands
            if not sub_command.config.is_default():
                formats_to_print.append((sub_command.args_format, False))

        app_name = command.application.config.name
        prefix = "    " if len(formats_to_print) > 1 else ""

        layout.add(Paragraph("<b>USAGE</b>"))
        with layout.block():
            for vars in formats_to_print:
                self._render_synopsis(layout, vars[0], app_name, prefix,
                                      vars[1])
                prefix = "or: "

            if command.has_aliases():
                layout.add(EmptyLine())
                self._render_aliases(layout, command.aliases)

        layout.add(EmptyLine())
コード例 #6
0
ファイル: abstract_help.py プロジェクト: sdispater/clikit
    def _render_global_options(
        self, layout, options
    ):  # type: (BlockLayout, Iterable[Option]) -> None
        layout.add(Paragraph("<b>GLOBAL OPTIONS</b>"))

        with layout.block():
            for option in options:
                self._render_option(layout, option)

        layout.add(EmptyLine())
コード例 #7
0
ファイル: abstract_help.py プロジェクト: sdispater/clikit
    def _render_arguments(
        self, layout, arguments
    ):  # type: (BlockLayout, Iterable[Argument]) -> None
        layout.add(Paragraph("<b>ARGUMENTS</b>"))

        with layout.block():
            for argument in arguments:
                self._render_argument(layout, argument)

        layout.add(EmptyLine())
コード例 #8
0
    def _render_description(self, layout,
                            help):  # type: (BlockLayout, str) -> None
        help = help.format(
            script_name=self._application.config.name or "console")

        layout.add(Paragraph("<b>DESCRIPTION</b>"))
        with layout.block():
            for paragraph in help.split("\n"):
                layout.add(Paragraph(paragraph))

        layout.add(EmptyLine())
コード例 #9
0
    def _render_usage(
            self, layout, application, args_format
    ):  # type: (BlockLayout, Application, ArgsFormat) -> None
        app_name = application.config.name

        layout.add(Paragraph("<b>USAGE</b>"))

        with layout.block():
            self._render_synopsis(layout, args_format, app_name)

        layout.add(EmptyLine())
コード例 #10
0
 def _render_name(self, layout,
                  application):  # type: (BlockLayout, Application) -> None
     layout.add(NameVersion(application.config))
     layout.add(EmptyLine())
コード例 #11
0
 def _render_sub_command_help(self, layout,
                              help):  # type: (BlockLayout, str) -> None
     layout.add(Paragraph(help))
     layout.add(EmptyLine())
コード例 #12
0
 def _render_sub_command_description(
         self, layout, description):  # type: (BlockLayout, str) -> None
     layout.add(Paragraph(description))
     layout.add(EmptyLine())