| 1 | ## Autogenerate Completions for CLI tools built with `click` |
| 2 | |
| 3 | |
| 4 | ### Add the integration to your CLI tool: |
| 5 | |
| 6 | ```bash |
| 7 | pip install click_complete_fig |
| 8 | ``` |
| 9 | |
| 10 | #### Add new subcommand to your CLI tool. |
| 11 | - You must pass in the root level CLI. |
| 12 | - The `add_completion_spec_command` function will add a new `generate-fig-spec` to the passed in `cli` |
| 13 | |
| 14 | ```python |
| 15 | from click_complete_fig import fig |
| 16 | |
| 17 | @click.group() |
| 18 | def cli(): |
| 19 | pass |
| 20 | |
| 21 | fig.add_completion_spec_command(cli) |
| 22 | ``` |
| 23 | |
| 24 | > NOTE: be sure to use `add_completion_spec_command` on a `@click.group` wrapped function and not on a `@click.command` wrapped one. |
| 25 | > Links: https://click.palletsprojects.com/en/8.0.x/commands/#commands-and-groups |
| 26 | |
| 27 | You can now automatically generate the completion spec skeleton by running the following command: |
| 28 | |
| 29 | ```bash |
| 30 | $CLI generate-fig-spec > $CLI.ts |
| 31 | ``` |
| 32 | |
| 33 | #### Generate a completion spec without adding a command to the CLI |
| 34 | |
| 35 | ```python |
| 36 | from click_complete_fig import fig |
| 37 | |
| 38 | @click.command() |
| 39 | def cli(): |
| 40 | pass |
| 41 | |
| 42 | fig.generate_completion_spec(cli) # Will print the spec as long as the .py script is run |
| 43 | ``` |
| 44 | |
| 45 | > NOTE: this works both with `@click.group` and `@click.command` wrapped functions. |