DocsIntegratingIntegrationsCommander

Fig Autocomplete & Commander.js

This tutorial will walk you through setting up Fig's integration with JS CLI framework, Commander.

Configure the @fig/complete-commander commander extension

# Go to your CLI's project
cd path/to/my/project

# Install the dependency
npm i -D @fig/complete-commander
# or if you are using yarn
yarn add -D @fig/complete-commander
// index.js
import { generateSpec } from '@fig/complete-commander'
import { program } from 'commander'

// Configure your program here...

if (process.env.NODE_ENV === 'development') {
  program
    .command('generate-fig-spec')
    .description('Generate a fig spec')
    .action(() => {
      console.log(generateSpec(program))
    })
}
program.parse()

Now running NODE_ENV=development node index.js generate-fig-spec will print the spec.

See other ways of using @fig/complete-commander extension in the package README

Next Steps: now that you have successfully configured the integration you can either push the spec to the autocomplete repo or push it to Fig's cloud.