Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commander

Package Overview
Dependencies
Maintainers
6
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commander

the complete solution for node.js command-line programs

  • 6.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
166M
decreased by-4.68%
Maintainers
6
Weekly downloads
 
Created

What is commander?

The commander npm package is a complete solution for node.js command-line interfaces. It provides a simple and flexible way to write CLI tools, allowing developers to parse command-line arguments, define commands, and automatically generate help messages.

What are commander's main functionalities?

Command parsing

This feature allows you to define options and parse command-line arguments. The code sample demonstrates how to set up a simple CLI with options for debugging, pizza size, and pizza type.

const { program } = require('commander');
program.version('0.0.1');
program
  .option('-d, --debug', 'output extra debugging')
  .option('-s, --small', 'small pizza size')
  .option('-p, --pizza-type <type>', 'flavour of pizza');
program.parse(process.argv);
if (program.debug) console.log(program.opts());

Subcommands

Commander allows you to define subcommands for your CLI application. The code sample shows how to define three subcommands: install, search, and list, with list being the default command.

const { program } = require('commander');
program
  .command('install [name]', 'install one or more packages')
  .command('search [query]', 'search with optional query')
  .command('list', 'list packages installed', { isDefault: true })
  .parse(process.argv);

Custom help

You can customize the help output of your CLI tool. The code sample demonstrates how to change the default help option and add a custom help command.

const { program } = require('commander');
program
  .helpOption('-e, --HELP', 'read more information')
  .addHelpCommand('assist', 'display help for command');
program.parse(process.argv);

Action handler

Commander allows you to attach an action handler to a command. The code sample shows how to define a command that takes a required argument and attaches an action handler to it.

const { program } = require('commander');
program
  .command('start <service>')
  .description('start the service')
  .action(function(service) {
    console.log('Starting service:', service);
  });
program.parse(process.argv);

Other packages similar to commander

Keywords

FAQs

Package last updated on 28 Aug 2020

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