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

commandpost

v1.4.0

Published

commandline option parser

Downloads

259,768

Readme

commandpost Circle CI

commandpost is a command-line options parser. This library is inspired by commander.

commander is very user-friendly, but not TypeScript-friendly. commandpost aims to improve this. Of course, commandpost can also be used from an ordinary JavaScript program. :+1:

Installation

$ npm install --save commandpost

How to Use

Basic Usage

$ cat cli.ts
import * as commandpost from "commandpost";

let root = commandpost
	.create<{ spice: string[]; }, { food: string; }>("dinner <food>")
	.version("1.0.0", "-v, --version")
	.description("today's dinner!")
	.option("-s, --spice <name>", "What spice do you want? default: pepper")
	.action((opts, args) => {
		console.log(`Your dinner is ${args.food} with ${opts.spice[0] || "pepper"}!`);
	});

commandpost
	.exec(root, process.argv)
	.catch(err => {
		if (err instanceof Error) {
			console.error(err.stack);
		} else {
			console.error(err);
		}
		process.exit(1);
	});

$ node cli.js --help
  Usage: dinner [options] [--] <food>

  Options:

    -s, --spice <name>  What spice do you want? default: pepper

$ node cli.js -s "soy sause" "fillet steak"
Your dinner is fillet steak with soy sause!

Commands

A top-level command is created by the commandpost.create function.

commandpost also supports sub-commands. A sub-command is created by using the topLevelCommand.subCommand method. Refer to this example for a demonstration.

commandpost can automatically generate help and command usage messages based on your configuration. For best results, it is recommended that you should set .version and .description for your top-level command.

Options

// shorthand & formal option with a required parameter. value is converted to string[].
cmd.option("-c, --config <configFile>", "Read setting from specified config file path");

// option with optional parameter. value is converted to string[].
cmd.option("-c, --config [configFile]", "Read setting from specified config file path");

// option without parameter (flag). option value is converted to boolean and defaults to `false`.
cmd.option("--suppress-warning", "Suppress warning");

// option with `--no-` prefix. option value is converted to boolean and defaults to true.
cmd.option("--no-type-checking", "Type checking disabled");

If you want to handle unknown options, you can use the .allowUnknownOption method.

Arguments

// required argument
commandpost.create<{}, { food: string; }>("dinner <food>");

// optional argument
commandpost.create<{}, { food: string; }>("dinner [food]");

// variadic argument
commandpost.create<{}, { foods: string[]; }>("dinner <food...>");

Examples

Contributing

This package's author, vvakame, is not a native English speaker. My first language is Japanese. If you find incorrect English, please send me a pull request.