def _make_options(ctx: click.Context) -> List[str]: """Creates the markdown lines describing the options for the command""" formatter = ctx.make_formatter() Command.format_options(ctx.command, ctx, formatter) # First line is redundant "Options" # Last line is `--help` option_lines = formatter.getvalue().splitlines()[1:-1] if not option_lines: return [] return ["Options:", "```code", *option_lines, "```"]
def show_usage(cmd: click.Command): """ Show the relevant usage and exit. The actual usage message is also specific to incomplete commands, thanks to using the click context. """ ctx = click.get_current_context() # TODO: disabling this next line for the time being because of inconsistent # behavior between this function and calling --help directly, which would produce # different output. still have to figure that out # ctx.max_content_width = MAX_CONTENT_WIDTH formatter = ctx.make_formatter() cmd.format_help_text(ctx, formatter) cmd.format_options(ctx, formatter) cmd.format_epilog(ctx, formatter) click.echo(formatter.getvalue().rstrip("\n")) ctx.exit(2)