Building Cli apps in Python

edit✏️

πŸŽ„This post has fully grown


Packages

Click

Inputs

Click primarily takes two forms of inputs Options and arguments. I think of options as keyword argument and arguments as regular positional arguments.

Option

  • typically aliased with a shorthand ('-v', '--verbose')

**From the Docs

To get the Python argument name, the chosen name is converted to lower case, up to two dashes are removed as the prefix, and other dashes are converted to underscores.

@click.command()
@click.option('-s', '--string-to-echo')
def echo(string_to_echo):
    click.echo(string_to_echo)
@click.command()
@click.option('-s', '--string-to-echo', 'string')
def echo(string):
    click.echo(string)

Argument

  • positional
  • required
  • no help text supplied by click

Yaspin

Yaspin Gif

Click Help Colors

Click Help Colors Example

Colorama

Colorama Example

Click DidYouMean



πŸ‘€ see an issue, edit this post on GitHub

If you found value in this post
and want to send a tip.

Buy Me A Coffee



tweet about this post and it will show up here.

    loading
←An IndieWeb Webring πŸ•ΈπŸ’β†’

.