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

pikud

v0.1.1

Published

Easily create command-line apps

Downloads

16

Readme

pikud

Create UNIX-style CLI applications in Node

pee-kood - Hebrew (not Danish, although I encourage you to look that up if you want a good laugh) for "command"

Inspired by https://github.com/codegangsta/cli

Installation

$ npm install --save pikud

Usage

A CLI app built with pikud consists of either a single command or unlimited nested commands. Each command can have its own flags. Flags are inherited from parent commands and can be overridden on the child if the child allows the same flag.

Flags

Flags are defined by a FlagSet, which consists of any mix of StringFlag, NumberFlag, or BoolFlag. See below examples.

Multiple

If you set allowMultiple:true when defining a StringFlag or NumberFlag, the flag will be parsed as an array rather than a single value (think Docker's -e flag). For example:

new StringFlag('environment', {
  alias:'e',
  allowMultiple:true
});
$ myapp -e "foo=bar" -e "baz=bing" -e "boop=scoop"

Help

Each command also automatically has a help flag (--help or -h) which will show the command's usage in a nice little table.

Actions

If a command has no sub-commands then it must have an action. The action takes any arguments passed via command line as well as the flags that were parsed. An action can either return a value, in which case that value will be written to the console at the end of execution, OR a Promise. If it returns a Promise, then pikud will handle it asynchronously.

Actions are bound to their commands using Function.call, so you can introspect the command or run this.help() to display the help text.

Examples

Single command

import { Command } from 'pikud';

let main = new Command('my-app', {
  action:(args, flags) => {
    console.log('Doing action with args', args, 'flags', flags);
  }
});

main.run(process.argv);
$ my-app arg1 arg2 arg3

With flags

import { FlagSet, StringFlag, BoolFlag, NumberFlag, Command } from 'pikud';

let main = new Command('my-app', {
  flags:new FlagSet([
    new StringFlag('foo', {
      alias:'f',
      defaultValue:'asdf',
      envVar:'FOO',
      description:'Which foo to use?'
    }),
    new BoolFlag('bar', {
      alias:'b',
      description:'Turn on the bar'
    })
  ]),
  action:(args, flags) => {
    console.log('Doing action with args', args, 'flags', flags);
  }
});

main.run(process.argv);
$ my-app -f "asdf" -b arg1 arg2 arg3

Sub commands

import { FlagSet, StringFlag, BoolFlag, NumberFlag, Command } from 'pikud';

let main = new Command('my-app', {
  flags:new FlagSet([
    new BoolFlag('foo', {
      alias:'f',
      description:'Turn on the foo'
    }),
    new BoolFlag('bar', {
      alias:'b',
      description:'Turn on the bar'
    })
  ]),
  subCommands:{
    cmd1:new Command('cmd1', {
      description:'Do command 1',
      flags: new FlagSet([
        new StringFlag('baz', {
          alias:'z',
          description:'Tell me the baz'
        })
      ]),
      action:(args, flags) => {
        console.log('Doing cmd 1 with ', args, flags);
      }
    })
  }
});

main.run(process.argv);
$ my-app -fb cmd1 --baz "This is the baz value" arg1 arg2 arg3