npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fig/complete-commander

v3.2.0

Published

Export commander command as a Fig spec

Downloads

685,292

Readme

Commander integration

A tool to speed up the workflow of converting Commander commands to Fig completion spec files.


Docs

generateCompletionSpec(command[, options]): string

Generate a completion spec from the provided command and return it a string.

  • command: a commander.Command object
  • options: 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 object

Usage

Using 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
}

Custom command

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 the figSpecCommandName option.

Options for generateCompletionSpec

Specify the fig command name

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.

Contributors

This integration was built by Federico Ciardi. Please see his repo for previous git history: https://github.com/fedeci/commander-to-fig.