| 1 | ## Autogenerate Completions for CLI tools built with `cement` |
| 2 | |
| 3 | This package generates [Fig |
| 4 | completions](https://github.com/withfig/autocomplete) for CLI tools built |
| 5 | on [Cement](https://builtoncement.com/). |
| 6 | |
| 7 | |
| 8 | ### Installation |
| 9 | |
| 10 | Install the integration as a dependency using pip: |
| 11 | |
| 12 | ```bash |
| 13 | pip install cement-complete-fig |
| 14 | ``` |
| 15 | |
| 16 | ### Usage |
| 17 | |
| 18 | Choose one of the methods below to add the `generate-fig-spec` |
| 19 | subcommand to the top level of your CLI tool. |
| 20 | |
| 21 | #### Method 1: Load as a Cement extension |
| 22 | |
| 23 | This package provides a [Cement |
| 24 | extension](https://docs.builtoncement.com/core-foundation/extensions-1) |
| 25 | for convenience called `'cement_complete_fig.ext.ext_complete_fig'` |
| 26 | which can be loaded in any of the ways cited in the linked documentation. |
| 27 | |
| 28 | Repeated here for convenience you can do one of the following: |
| 29 | |
| 30 | 1. Add the extension to the `Meta` of your `App` object: |
| 31 | |
| 32 | ```python |
| 33 | from cement import App |
| 34 | |
| 35 | class MyApp(App): |
| 36 | class Meta: |
| 37 | label = 'myapp' |
| 38 | extensions = [ |
| 39 | ..., |
| 40 | 'cement_complete_fig.ext.ext_complete_fig' |
| 41 | ] |
| 42 | ``` |
| 43 | |
| 44 | |
| 45 | 2. Manually load the extension before running your app: |
| 46 | |
| 47 | ```python |
| 48 | from cement import App |
| 49 | |
| 50 | with App('myapp') as app: |
| 51 | app.ext.load_extension('cement_complete_fig.ext.ext_complete_fig') |
| 52 | |
| 53 | app.run() |
| 54 | ``` |
| 55 | |
| 56 | 3. Add the extension to your app configuration file (e.g. `.myapp.conf`): |
| 57 | |
| 58 | ```toml |
| 59 | [myapp] |
| 60 | exensions = cement_complete_fig.ext.ext_complete_fig |
| 61 | ``` |
| 62 | |
| 63 | #### Method 2: Bind the controller manually |
| 64 | |
| 65 | You can also add the `GenerateFigSpecController` manually as a handler to your |
| 66 | app: |
| 67 | |
| 68 | ```python |
| 69 | from cement import App |
| 70 | from cement_complete_fig import GenerateFigSpecController |
| 71 | |
| 72 | class MyApp(App): |
| 73 | class Meta: |
| 74 | label = 'myapp' |
| 75 | handlers = [ |
| 76 | ..., |
| 77 | GenerateFigSpecController |
| 78 | ] |
| 79 | |
| 80 | with MyApp() as app: |
| 81 | app.run() |
| 82 | ``` |
| 83 | |
| 84 | ### Generating the spec file |
| 85 | |
| 86 | Once you've added the integration you will have new subcommand nested |
| 87 | under your base handler. When this subcommand is invoked it will print |
| 88 | a Fig spec. |
| 89 | |
| 90 | To save your completion spec skeleton to a file, run the following: |
| 91 | |
| 92 | ```bash |
| 93 | myapp generate-fig-spec > myapp.ts |
| 94 | ``` |