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

@cthru/cmdr

v1.4.7

Published

A simple solution for single or multi-command node cli scripts.

Downloads

19

Readme

cmdr

A simple solution for single or multi-command node cli scripts.

Version Downloads/week License

Description

cmdr is a utility to make it easy to create cli apps with command line parsing

Scaffolding

To get going quickly with a new cli command:

  • npx @cthru/cmdr create:single --init <command> for a single command with npm init and dependency installation
  • npx @cthru/cmdr create:multi --init <app> <command> for a multi command app with npm init and dependency installation

Examples

Single-command app

const {App, Param, Flag, Argument} = require('@cthru/cmdr')

const hello=(options)=>{
	padding=parseInt(options.padding)
	out = `${isNaN(padding)?'':Array(padding).join(' ')}Hello ${options.name}`
	options.capitalize && (out = out.toUpperCase())
	console.log(out)
}


const app =  new App(
	{
		name : "Hello world test",
		command: 'test',
		version: '1.0',
		description: "This app only exists as a proof of concept",
		callback: hello
	},
	new Param(
		{
			name:'name',
			description: 'Your first name'
		}
	),
	new Flag(
		{
			name: 'capitalize',
			short: 'C',
			description: 'Capitalize the output'
		}
	),
	new Argument(
		{
			name: 'padding',
			short: 'P',
			description: 'Make some padding before the output',
			defaultValue: '0'
		}
	)
)

app.run()

Multi-command App

cmdr also allows for multiple commands in the same app. The following example has two commands

index.js


const app =  new App(
	{
		name : "Hello World Test",
		command: 'test',
		version: '1.0',
		description: "This app only exists as a proof of concept"
	},
	require('./hello'),
	require('./bye')
)

app.run()

hello.js

const {Command, Argument, Flag, Param} = require('@cthru/cmdr')

const hello=(options)=>{
	padding=parseInt(options.padding)
	out = `${isNaN(padding)?'':Array(padding).join(' ')}Hello ${options.name}`
	options.capitalize && (out = out.toUpperCase())
	console.log(out)
}

const command = new Command(
	{
		command: 'hello',
		description: 'A simple Hello world app',
		callback: hello
	},
	new Param(
		{
			name:'name',
			description: 'Your first name'
		}
	),
	new Flag(
		{
			name: 'capitalize',
			short: 'C',
			description: 'Capitalize the output'
		}
	),
	new Argument(
		{
			name: 'padding',
			short: 'P',
			description: 'Make some padding before the output',
			defaultValue: '0'
		}
	)
)

module.exports = command

bye.js

const {Command, Argument, Flag, Param} = require('@cthru/cmdr')

const bye=(options)=>{
	padding=parseInt(options.padding)
	out = `${isNaN(padding)?'':Array(padding).join(' ')}Goodbye ${options.name}`
	options.capitalize && (out = out.toUpperCase())
	console.log(out)
}

const command = new Command(
	{
		command: 'bye',
		description: 'A simple Bye world app',
		callback: bye
	},
	new Param(
		{
			name:'name',
			description: 'Your first name'
		}
	),
	new Flag(
		{
			name: 'capitalize',
			short: 'C',
			description: 'Capitalize the output'
		}
	),
	new Argument(
		{
			name: 'padding',
			short: 'P',
			description: 'Make some padding before the output',
			defaultValue: '0'
		}
	)
)

module.exports = command

TODO

  • argument validation
  • ~~--argument=20 format support, currently only allows --argument 20 format~~
  • interactive mode
  • ~~more flexible help generation~~