Skip to content

Way to render CLI usage examples in docstrings #2762

Closed

Description

@wyardley

Is there an easy way to define CLI usage examples, and display them in a noticeable way (let's say in bold output)? This could either be inline inside the main docstring, like this:

def main(foo):
    """Run the program.

         Do some stuff

         Run program with flag foo
         `./program.py --foo`

(where the bit in backticks would get rendered in bold or something)

or via some kind of @click.usage or @click.example decorator?

Activity

  1. davidism commented on Aug 9, 2024

    @davidism
    Member
  2. wyardley commented on Aug 9, 2024

    @wyardley
    Author

    @davidism I'm normally familiar with Sphinx for web-based / html docs -- will this work for the inline docs (via ./command --help etc.)? Is there an example of how a usage example would be defined?

    Also, sorry if I'm being obtuse, but based on the docs above, I couldn't find a specific way of including command examples via, say, a decorator, or extracting them from the help text.

    My goal is to be able to have usage examples (of how the program and its flags are to be used) in the inline console based docs.

  3. davidism commented on Aug 9, 2024

    @davidism
    Member

    You would write them in the docstring, which gets turned into the command description.

  4. locked and limited conversation to collaborators on Aug 9, 2024
  5. converted this issue into a discussion #2763 on Aug 9, 2024
  6. added
    docsUpdates to documentation, readme, docstrings, typos
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsUpdates to documentation, readme, docstrings, typos

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions