New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@withfig/commander

Package Overview
Dependencies
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@withfig/commander

Export commander command as a Fig spec

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

Commander integration

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


Docs

generateFigSpec(command, filename[, options]): void
  • command: a commander.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 to process.cwd()
    • figSpecCommandName: specify the name of the command used to generate the fig spec (see). It defaults to 'generateFigSpec'

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 { generateFigSpec } from '@withfig/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') {
  generateFigSpec(program, 'babel-spec.ts' [, options])
}

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 generateFigSpec is run from a Terminal.

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('generateFigSpec')
    .description('Generate a fig spec')
    .action(() => {
      generateFigSpec(program, 'eslint-spec.ts' [, options])
    })
}
program.parse()

NOTE: the command can be called whatever you want, but if you specify a name different from 'generateFigSpec' you should set the figSpecCommandName option.

Options

Specify the working directory

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') })

Specify the fig command name

When creating a custom command to generate a Fig spec whose name is different from 'generateFigSpec' 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(() => {
      generateFigSpec(program, 'eslint-spec.ts', { 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.

Keywords

FAQs

Package last updated on 15 Mar 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc