diff --git a/README.md b/README.md index 02d92c7..827239b 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ npm install cli-er - [**run(args?)**](./docs/api.md#runargs): parse the given arguments and execute the corresponding script found in the calculated location. Integrates help and version generation. - [**help(location?)**](./docs/api.md#helplocation): generate help based on the definition. Can be scoped to a namespace/command. - [**version()**](./docs/api.md#version): generate a formatted version of the application's version. +- [**completions()**](./docs/features.md#bash-completion): output bash-completion script contents. #### Glossary - **Namespace**: is used to group commands, but cannot be invoked. Can contain other namespaces, commands or options. diff --git a/docs/api.md b/docs/api.md index e810f5f..43e37d1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -189,4 +189,9 @@ _**TIP**: any `DefinitionElement` can be hidden from the generated help by using Prints the formatted version of the current cli application: finds the package.json for the current application, and prints its name and version. > **Note** -> version-generation option is auto-included by default. This can be configured via [`CliOptions.version`](/docs/cli-options.md#versionautoinclude) \ No newline at end of file +> version-generation option is auto-included by default. This can be configured via [`CliOptions.version`](/docs/cli-options.md#versionautoinclude) + + +## completions() + +Generates and outputs bash-completion script contents. This can instead be included as a command and be managed by `Cli.run`, check: [`bash completion`](/docs/features.md#bash-completion) \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 76510ef..810abb1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ import CliLogger from "./cli-logger"; import { ERROR_MESSAGES } from "./cli-errors"; import { CLI_MESSAGES, formatMessage } from "./cli-messages"; import { defineCommand, CommandOptions } from "./extract-options-type"; +import { generateCompletions } from "./bash-completion"; export default class Cli { static logger: ICliLogger = new CliLogger(); @@ -175,6 +176,12 @@ export default class Cli { version() { formatVersion(this.options); } + /** + * Output bash-completion script contents + */ + completions() { + generateCompletions({ definition: this.definition, cliOptions: this.options }); + } } // Export of types not used anywhere in the codebase