# muxrpcli

> command-line interface to mux rpc servers

Latest version **3.1.2** (published 2019-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install muxrpcli
pnpm add muxrpcli
yarn add muxrpcli
bun add muxrpcli
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2019-08-05 |
| First published | 2015-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Paul Frazee |
| Maintainers | ahdinosaur, aljoscha-meyer, andregarzia, arj03, cel, christianbundy, cryp7ix, dominictarr, happy0, kyphae, mixmix, mmckegg, noffle, pfraze, pfrazee, pietgeursen, regular, staltz, vtduncan |
| Keywords | muxrpc, rpc, cli |

## Links

- npm: https://www.npmjs.com/package/muxrpcli
- npm.io page: https://npm.io/package/muxrpcli

## Dependencies (6)

- [cont](https://npm.io/package/cont.md) ^1.0.3
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [word-wrap](https://npm.io/package/word-wrap.md) ^1.2.3
- [pull-stream](https://npm.io/package/pull-stream.md) ^3.6.9
- [muxrpc-usage](https://npm.io/package/muxrpc-usage.md) ^2.0.1
- [stream-to-pull-stream](https://npm.io/package/stream-to-pull-stream.md) ^1.7.3

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 3.1.2 (latest) — 2019-08-05
- 3.1.1 — 2019-05-23
- 3.1.0 — 2019-05-11
- 3.0.0 — 2019-03-31
- 2.0.0 — 2019-03-31
- 1.1.0 — 2016-10-23
- 1.0.5 — 2016-01-21
- 1.0.4 — 2015-10-06
- 1.0.3 — 2015-09-15
- 1.0.2 — 2015-09-14
- 1.0.1 — 2015-09-13
- 1.0.0 — 2015-09-13

## README

# muxrpcli

Command-line interface to [muxrpc](https://github.com/ssbc/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](https://www.npmjs.com/package/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

```js
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
```

---
_Source: https://npm.io/package/muxrpcli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
