Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@fig/complete-commander
Advanced tools
Readme
A tool to speed up the workflow of converting Commander commands to Fig completion spec files.
generateCompletionSpec(command[, options]): string
Generate a completion spec from the provided command and return it a string.
command
: a commander.Command
objectoptions
: an object containing the following optional properties:
figSpecCommandName
: specify the name of the command used to generate the fig spec (see). It defaults to 'generate-fig-spec'
addCompletionSpecCommand(command): void
Add a new Subcommand to the provided command that will print a spec generated when invoked through $CLI generate-fig-spec
.
command
: a commander.Command
objectUsing this library is as simple as calling a function. The snippet of code below generates a new spec each time the executable file is run.
import { program } from 'commander'
import { generateCompletionSpec } from '@fig/complete-commander'
program
.name('babel')
.description('The compiler for writing next generation JavaScript')
.version('7.16.0')
.argument('<file>', 'file to compile')
// Do not generate if production env
if (process.env.NODE_ENV === 'development') {
const spec = generateCompletionSpec(program) // write the generated spec to a file or print it to the console
}
You can also provide a custom command that generates a spec file when called. For example, the program below generates the Fig spec when eslint generate-fig-spec
is run from a Terminal.
import { program } from 'commander'
import { addCompletionSpecCommand } from '@fig/complete-commander'
program
.name('eslint')
.description('Find and fix problems in your JavaScript code')
.version('8.0.0')
.argument('<file>', 'file to lint')
if (process.env.NODE_ENV === 'development') {
addCompletionSpecCommand(program)
}
program.parse()
NOTE: the command can be called whatever you want, but if you specify a name different from
'generate-fig-spec'
you should set thefigSpecCommandName
option.
generateCompletionSpec
When creating a custom command to generate a Fig spec whose name is different from 'generateCompletionSpec'
you want to avoid including it in the generated file. This option helps you do that.
program
.name('eslint')
.description('Find and fix problems in your JavaScript code')
.version('8.0.0')
.argument('<file>', 'file to lint')
if (process.env.NODE_ENV === 'development') {
program
.command('createSpec') // this command will not be included in the generated spec
.description('Generate a fig spec')
.action(() => {
generateCompletionSpec(program, { figSpecCommandName: 'createSpec' })
})
}
program.parse()
p.s. this tool has been written for commander@8
, but should work in the most of the previous versions too.
This integration was built by Federico Ciardi. Please see his repo for previous git history: https://github.com/fedeci/commander-to-fig.
FAQs
Export commander command as a Fig spec
The npm package @fig/complete-commander receives a total of 73,560 weekly downloads. As such, @fig/complete-commander popularity was classified as popular.
We found that @fig/complete-commander demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.