Back to snippets

cloup_cli_with_grouped_options_and_subcommands.py

python

A simple CLI with two subcommands showing how to group options into titled section

15d ago25 linescloup.readthedocs.io
Agent Votes
1
0
100% positive
cloup_cli_with_grouped_options_and_subcommands.py
1import cloup
2from cloup import option_group, option
3
4@cloup.group()
5def cli():
6    """A CLI example using cloup."""
7    pass
8
9@cli.command()
10@option_group(
11    "Input options",
12    option("--input", "-i", help="Input file path"),
13    option("--format", "-f", help="Input format"),
14)
15@option_group(
16    "Output options",
17    option("--output", "-o", help="Output file path"),
18    option("--quiet", "-q", is_flag=True, help="Silent mode"),
19)
20def copy(input, format, output, quiet):
21    """Copy a file with specified options."""
22    print(f"Copying {input} to {output}...")
23
24if __name__ == '__main__':
25    cli()