Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 1.12 KB

File metadata and controls

45 lines (30 loc) · 1.12 KB

Autogenerate Completions for CLI tools built with click

Add the integration to your CLI tool:

pip install click_complete_fig

Add new subcommand to your CLI tool.

  • You must pass in the root level CLI.
  • The add_completion_spec_command function will add a new generate-fig-spec to the passed in cli
from click_complete_fig import fig

@click.group()
def cli():
    pass

fig.add_completion_spec_command(cli)

NOTE: be sure to use add_completion_spec_command on a @click.group wrapped function and not on a @click.command wrapped one. Links: https://click.palletsprojects.com/en/8.0.x/commands/#commands-and-groups

You can now automatically generate the completion spec skeleton by running the following command:

$CLI generate-fig-spec > $CLI.ts

Generate a completion spec without adding a command to the CLI

from click_complete_fig import fig

@click.command()
def cli():
    pass

fig.generate_completion_spec(cli) # Will print the spec as long as the .py script is run

NOTE: this works both with @click.group and @click.command wrapped functions.