def format_example(example: str, formatter: click.HelpFormatter) -> None: with formatter.section(click.style("Examples", bold=True, underline=False)): for line in example.splitlines(): is_comment = line.startswith("#") if is_comment: formatter.write_text("\b\n" + click.style(line, dim=True)) else: formatter.write_text("\b\n" + " ".join(shlex.split(line)))
def format_options(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: self.format_commands(ctx, formatter) formatter.write_paragraph() formatter.write_text( 'Use "neuro <command> --help" for more information about a given command.' ) formatter.write_text( 'Use "neuro --options" for a list of global command-line options ' "(applies to all commands).")
def format_options(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: self.format_commands(ctx, formatter) formatter.write_paragraph() formatter.write_text( f'Use "{ctx.info_name} help <command>" for more information ' "about a given command or topic.") formatter.write_text( f'Use "{ctx.info_name} --options" for a list of global command-line ' "options (applies to all commands).")
def format_help_text(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: formatter.write_paragraph() alias_cmd = self.alias["exec"] formatter.write_text("Alias for " + click.style(f'"{alias_cmd}"', bold=True)) help = self.alias.get("help") if help is not None: formatter.write("\n") formatter.write_text(help)
def format_synopsis(self, formatter: click.HelpFormatter) -> None: """Wirte the synopsis to the formatter if exist. Arguments: formatter: The help formatter of the command. """ if not self.synopsis: return with formatter.section("Synopsis"): for example in self.synopsis: formatter.write_text(example)
def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: self.format_usage(ctx, formatter) formatter.write_paragraph() assert ctx.parent is not None alias_cmd = self.alias["cmd"] formatter.write( "Alias for " + click.style(f'"{ctx.parent.info_name} {alias_cmd}"', bold=True)) formatter.write_paragraph() help = self.alias.get("help") if help is not None: formatter.write_paragraph() formatter.write_text(help) self.format_options(ctx, formatter)
def format_help_text(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: """Writes the help text to the formatter if it exists.""" help = self.help # type: ignore deprecated = self.deprecated # type: ignore if help: help_text, *examples = split_examples(help) if help_text: formatter.write_paragraph() with formatter.indentation(): if deprecated: help_text += DEPRECATED_HELP_NOTICE formatter.write_text(help_text) examples = [example.strip() for example in examples] for example in examples: format_example(example, formatter) elif deprecated: formatter.write_paragraph() with formatter.indentation(): formatter.write_text(DEPRECATED_HELP_NOTICE)
def format_options(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: # Group options first groups = defaultdict(list) for param in self.get_params(ctx): rv = param.get_help_record(ctx) if rv is not None: if isinstance(param, GroupedOption): group = param.group else: group = ParameterGroup.generic groups[group].append(rv) # Then display groups separately with optional description for group in ParameterGroup: opts = groups[group] group_name, description = group.value with formatter.section(f"{group_name} options"): if description: formatter.write_paragraph() formatter.write_text(description) formatter.write_paragraph() formatter.write_dl(opts)
def format_help_text(self, ctx: Context, formatter: Formatter) -> None: """ Writes the help text to the formatter if it exists. """ formatter.write_paragraph() formatter.write_text(self.help)
def format_help_text(text: str, formatter: click.HelpFormatter): text = inspect.cleandoc(text).partition("\f")[0] formatter.write_paragraph() with formatter.indentation(): formatter.write_text(text)