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

cmd-line

v1.0.2

Published

Allows you to create command line tools fast and easy.

Downloads

13

Readme

CMDLine

NPM VersionBuild StatusPRs Welcome

bitHound Overall ScorebitHound DependenciesbitHound Dev Dependencies

Code ClimateTest CoverageIssue Count

semantic-releaseCommitizen friendlyjs-happiness-style

CMDLine Allows you to define nodejs command line tools. It works by sing a folder structure and lets you call generator function (async if using babel), normal function and also function that return promises. When runnig in the target folder it will try to load all the files under the /target/commands/ so your final users can easily extend your cli tool.

Installation

npm install cmd-line -S

Usage

/* /mycommand */
#!/usr/bin/env node
const CMD = require('cmd-line').default;
const cmdtest = new CMD('mycommand');
let promise = cmdtest.loadcommands(__dirname)
	.includehostcommands()
	.execute(process.argv);

Definign a Command

/* /commands/subcmd1.js */
exports.default = {
	cmd: __filename,
	args: ['arg1', '?arg2'],
	options: [
		['-f','--force', 'Override it!'],
		['--port','--port comport com4', 'Select your COMPort.']
	],
	description: 'My awsome command',
	action: (arg1, arg2, options) => {
		return 1;
	}
};

mycommand subcmd1 arg1 -f

  1. cmd[ string ]: The name of the command that will be reconigzed.
  2. args[ array(string) ]: Argumments that will be passed to the command, by placing "?" before a command you make it optional.
  3. options[ array(array(string)) ]: The options that the program will receive.
  4. option[ array(string) ].
  5. First value: Is the short tag.
  6. Second value: Is the tag. It can have a variable receiver and a defvalue. Tag must be prepend with "--" varname and defvalue a separeted by " ".
  7. Third value: Is tehe description of the option.

Automatic Help

By default a -h | --help option is added and it will generete an automatic text.

mycommand subcmd1
mycommand subcmd1 -h

Outputs:

mycommand subcmd1 arg1 ?arg2 [options]
  My awsome command
	-h  --help    Show the help for this command
	-f  --force   Override it!
	--port        comport Select your COMPort.

Customizing Help

If you need it you can change the template for the help like this:

/* /mycommand */
// ...
cmdtest.loadcommands(__dirname)
	.includehostcommands()
	.template(function (name, cmd, args, options, description) {
		return `${name} ${cmd} ${args} [ options ]\n  ${description}\n${options.join('\n')}`;
	})
	.arguments((args) => args.join(' '))
	.options((option, longest, varlen) => {
		let {shortag, tag, variable, description} = option;
		return `    ${shortag} ${tag} ${variable} ${description}`;
	})
	.execute(process.argv)

The argumments and the options have a serializer, you can change it this way

/* /mycommand */
// ...
cmdtest.loadcommands(__dirname)
	.includehostcommands()
	.arguments((args) => args.join(' '))
	// longest is the space used by the tag and the shortag
	// varlen is the space used by the varname
	.options((option, longest, varlen) => {
		let {shortag, tag, variable, description} = option;
		return `    ${shortag} ${tag} ${variable} ${description}`;
	})
	.execute(process.argv)

Customizing help by command

Another option is to custumaize only one command help.

/* /commands/subcmd2.js */
const Command = require('cmd-line/lib/Commad').default;

exports.default = new Command(__filename, 'Hola Mundo')
	.Args('project', '?location')
	.Options([
		['--port', '--port portname 62626', 'Chosses a port'],
		['-d', '--dir location', 'Chosses a port'],
		['-f', '--force', 'Force'],
		['-r', '--recursive', 'Recursive'],
		['-sb', '--skip-bower', 'Chosses a port']
	])
	.Action(function* (project, location, options) {
		let timeout = new Promise(function (resolve) {
			setTimeout(() => {
				resolve('casa');
			}, 1000);
		});
		yield timeout;
    	return 100;
	}).Help((Rendered Help) => {
		console.log('My Custom Help');
	});
};
mycommad subcmd2 -h

Outputs:
My Custom Help