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

muxrpcli

v3.1.2

Published

command-line interface to mux rpc servers

Downloads

202

Readme

muxrpcli

Command-line interface to muxrpc servers. Works by converting the command-line parameters into args for the RPC calls. Also adds some standard behaviors for usage calls.

CLI Parameters

Parameters are parsed with minimist. The first positional param is mapped to the rpc command. Any subsequent positional params are passed as arguments. Then, the object constructed by the named parameters (if there are any) is passed as the last argument.

Examples:

$ program command arg1 arg2
invokes `server.command("arg1", "arg2")`

$ program command -a beep -b boop
invokes `server.command({ a: "beep", b: "boob" })'

$ program command arg1 arg2 -a beep -b boop
invokes `server.command("arg1", "arg2", { a: "beep", b: "boob" })'

$ program command -a beep -b boop arg1 arg2 
invokes `server.command("arg1", "arg2", { a: "beep", b: "boob" })'

If a stream is supplied to stdin, it will be parsed as JSON and used instead of the CLI parameters.

$ echo '{"a":"beep","b":"boop"}' | program command
invokes `server.command({ a: "beep", b: "boob" })'

Usage calls

Usage-calls are the help which is output when a command fails, or when help is requested. They are used in the following situations:

  • If the command does not exist in the RPC server's manifest, does a top-level usage call.
  • If the command responses with a TypeError, UsageError, BadParamError, or BadArgError, does a usage call for that command.
  • If the -h or --help switches are given, does a toplevel or command usage call.

A usage-call is a call to the usage(cmd) function on the RPC server. A 'top-level' usage call will leave cmd falsey. The usage method should return a string to display.

Example rpc server

var zerr = require('zerr')
var MissingArgError = zerr('BadArg', '"%" is required')
var BadTypeError = zerr('BadArg', '"%" must be a valid %')

var manifest = {
  usage: 'sync',
  whoami: 'sync',
  ping: 'async'
}
var api = {}
// muxrpc(null, manifest)(api) is called

api.usage = function (cmd) {
  switch (cmd) {
    case 'whoami':
      return 'whoami. get your profile info.'
    case 'ping':
      return 'ping {target} [-n times]. send `n` pings to `target`, defaults to 1'
  }
  return [
    'myexample usage:'
    ' - ' + api.usage('whoami'),
    ' - ' + api.usage('ping')
  ].join('\n')
}

api.whoami = function() { return 'bob, obviously' }

api.ping = function(target, opts, cb) {
  if (!target) return cb(MissingArgError('target'))
  if (!isAddress(target)) return cb(BadTypeError('target', 'address'))
  
  var n = 1
  if (opts && opts.n) {
    n = +opts.n
    if (isNaN(n)) return cb(BadTypeError('n', 'number'))
  }

  // ...
}

Here's how a session would behave with this server:

$ myexample
myexample usage:
 - whoami. get your profile info.
 - ping {target} [-n times]. send `n` pings to `target. defaults to 1

$ myexample whoami -h
whoami. get your profile info.

$ myexample ping -h
ping {target} [-n times]. send `n` pings to `target. defaults to 1

$ myexample whoami
bob, obviously

$ myexample ping 127.0.0.1
...

$ myexample ping 1123123123
[BadArgError: "target" must be a valid address]
ping {target} [-n times]. send `n` pings to `target. defaults to 1


$ myexample ping 127.0.0.1 -n foobar
[BadArgError: "n" must be a valid number]
ping {target} [-n times]. send `n` pings to `target. defaults to 1