⚠️ NOTE: this integration is now @withfig/commander
and has moved into the the autocomplete-tools monorepo.
A tool to speed up the workflow of converting Commander commands to Fig completion spec files.
generateFigSpec(command, filename[, options]): void
-
command
: acommander.Command
object -
filename
: the output filename of the completion spec file -
options
: an object containing the following optional properties:-
cwd
: specify the working directory in which the file will be saved. It defaults toprocess.cwd()
-
Using this library is as simple as importing a function and calling it.
import { program } from 'commander'
import { generateFigSpec } from '@withfig/commander'
program
.name('babel')
.description('The compiler for writing next generation JavaScript')
.version('1.0.0')
.argument('<file>', 'file to compile')
generateFigSpec(program, 'babel-spec.ts')
For example you may want to generate the file in an home directory subfolder for testing purpose.
import path from 'path'
import os from 'os'
...
// this will output to ~/generated/babel-spec.ts
generateFigSpec(program, 'babel-spec.ts', { cwd: path.join(os.homedir(), 'generated') })
p.s. this tool has been written for commander@8
, but should work in the most of the previous versions too.