Best practices for building CLI applications with Click including commands, groups, options, and testing.
Best practices for building CLI applications with Click including commands, groups, options, and testing.
Apply this skill when building command-line interfaces with Click — commands, groups, options, arguments, and prompts.
@click.command() for single commands, @click.group() for multi-command CLIs.@click.option() and positional args with @click.argument().help= on every option and command for auto-generated help text.envvar= to allow environment variable fallback for sensitive options.@click.group() and group.add_command().@click.pass_context to share state between group and subcommands.click.Path(exists=True), click.Choice([...]), click.IntRange()).click.testing.CliRunner() for testing commands without subprocess overhead.result.exit_code and result.output.mix_stderr=False to test stderr separately.sys.exit() — use click.exceptions.Exit or return from the command.print() — use click.echo() for proper encoding handling.KeyboardInterrupt / abort prompts gracefully.