1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
import rich_click as click
click.rich_click.OPTION_GROUPS = {
"03_groups_sorting.py": [
{
"name": "Basic usage",
"options": ["--type", "--output"],
},
{
"name": "Advanced options",
"options": ["--help", "--version", "--debug"],
# You can also set table styles at group-level instead of using globals if you want
"table_styles": {
"row_styles": ["bold", "yellow", "cyan"],
},
},
],
"03_groups_sorting.py sync": [
{
"name": "Inputs and outputs",
"options": ["--input", "--output"],
},
{
"name": "Advanced usage",
"options": ["--overwrite", "--all", "--help"],
},
],
}
click.rich_click.COMMAND_GROUPS = {
"03_groups_sorting.py": [
{
"name": "Main usage",
"commands": ["sync", "download"],
},
{
"name": "Configuration",
"commands": ["config", "auth"],
},
]
}
@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
@click.option(
"--type",
default="files",
show_default=True,
required=True,
help="Type of file to sync",
)
@click.option(
"--debug/--no-debug",
"-d/-n",
default=False,
show_default=True,
help="Show the debug log messages",
)
@click.version_option("1.23", prog_name="mytool")
def cli(type, debug):
"""
My amazing tool does all the things.
This is a minimal example based on documentation
from the 'click' package.
You can try using --help at the top level and also for
specific subcommands.
"""
print(f"Debug mode is {'on' if debug else 'off'}")
@cli.command()
@click.option("--input", "-i", required=True, help="Input path")
@click.option("--output", "-o", help="Output path")
@click.option("--all", is_flag=True, help="Sync all the things?")
@click.option("--overwrite", is_flag=True, help="Overwrite local files")
def sync(input, output, all, overwrite):
"""Synchronise all your files between two places."""
print("Syncing")
@cli.command()
@click.option("--all", is_flag=True, help="Get everything")
def download(all):
"""Pretend to download some files from somewhere."""
print("Downloading")
@cli.command()
def auth():
"""Authenticate the app."""
print("Downloading")
@cli.command()
def config():
"""Set up the configuration."""
print("Downloading")
if __name__ == "__main__":
cli()
|