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())
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())
def _render_sub_commands( self, layout, sub_commands): # type: (BlockLayout, CommandCollection) -> None layout.add(Paragraph("<b>COMMANDS</b>")) with layout.block(): for sub_command in sorted(sub_commands, key=lambda c: c.name): self._render_sub_command(layout, sub_command)
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())
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())
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())
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())
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())
def _render_aliases(self, layout, aliases): # type: (BlockLayout, Iterable[str]) -> None layout.add(Paragraph("aliases: {}".format(", ".join(aliases))))
def _render_sub_command_help(self, layout, help): # type: (BlockLayout, str) -> None layout.add(Paragraph(help)) layout.add(EmptyLine())
def _render_sub_command_description( self, layout, description): # type: (BlockLayout, str) -> None layout.add(Paragraph(description)) layout.add(EmptyLine())
def prose_version(self, event, event_name, dispatcher): if event.args.is_option_set("version"): p = Paragraph("Prose version <c1>{}</c1>".format(__version__)) p.render(event.io)