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

@kvnlnt/spawn

v1.0.4

Published

The CLI for CLIs

Downloads

12

Readme

Spawn

Features

  1. Create your own cli
  2. Auto generates guide for cli and individual commands
  3. Interactive mode (using -i flag)
  4. Argument defaults

Install

npm i @kvnlnt/spawn

Usage

mycli.js

// the lib
const cli = require("@kvnlnt/spawn");

// add a command, add an argument, a callback and an example
cli
  .command("hello", "Prints hello")
  .argument("output", "o", "Hello to")
  .callback(resp => console.log("Hello,", resp.output))
  .example("hello -o=World", "Prints; Hello World");

// add another
cli
  .command("goodbye", "Prints goodbye")
  .argument("output", "o", "Goodbye to")
  .callback(resp => console.log("Goodbye,", resp.output))
  .example("goodbye -o=World", "Prints: Goodbye World");

// set the default command
cli.defaultCommand("help");

// run the cli
cli.run();

Now set up your tool to be a cli with npm link and you'll get something like this

mycli hello -o=You
# result => Hello You

Methods

All methods are meant to be chained. This is to support a clean api. To keep things organized it's recommended that you keep your callbacks as external scripts. It keep my in a tasks folder.

command(name, desc)

Adds a command

| Arg | Type | Desc | | ---- | ------ | ---------------------- | | name | string | name of command | | desc | string | description of command |

argument(name, abbr, desc, def)

Adds an argument to last added command

| Arg | Type | Desc | | ---- | -------- | ------------------------- | | name | string | name of argument | | abbr | string | abbreviated argument name | | desc | string | description of argument | | def | anything | default value |

callback(f)

Adds callback to last added command

| Arg | Type | Desc | | --- | -------- | ---------------------------------------- | | f | function | function called when command is executed |

example(cmd, desc)

Adds example to last added command

| Arg | Type | Desc | | ---- | ------ | --------------- | | cmd | string | example command | | desc | string | description |

defaultCommand(cmd)

Sets default command

| Arg | Type | Desc | | --- | ------ | --------------- | | cmd | string | name of command |

run()

Runs the cli

printGuide()

This is the auto generated guide. To use it, assign it as a callback. Something like this:

cli.command("guide", "Prints guide").callback(cli.printGuide);

printCommandGuide()

This is the autogenerated guide for a command. Commands are bound to the cli instance and therefore are available inside the callback as this.printCommandGuide. Just pass in the string name of the command. Here's an example:

// your callback
function myCallback(resp) {
  if (resp.help === true) return this.printCommandGuide("myCallback");
  console.log(resp.output);
}

// your cli
cli
  .command("myCallback", "does stuff")
  .argument("help", "h", "Output help", false)
  .callback(myCallback);

The following will output the command's guide:

mycli myCallback -h

Flags

-i, Interactive Mode

You can pass the -i flag without a command and use your tool interactively, like this:

mycli -i

Examples

All examples are in the Examples folder.