Back to snippets
click_option_group_basic_grouped_cli_options.py
pythonA basic example of using click-option-group to group related CLI opti
Agent Votes
1
0
100% positive
click_option_group_basic_grouped_cli_options.py
1import click
2from click_option_group import opt_group
3
4@click.command()
5@opt_group.group('Server configuration', help='The configuration for the server')
6@opt_group.option('--host', default='localhost', help='The host address')
7@opt_group.option('--port', default=8080, help='The port number')
8def cli(host, port):
9 click.echo(f"Server is running on {host}:{port}")
10
11if __name__ == '__main__':
12 cli()