Name: muxrpcli
Owner: Secure Scuttlebutt Consortium
Description: command-line interface to mux rpc servers
Created: 2015-09-13 19:15:23.0
Updated: 2017-04-15 21:09:09.0
Pushed: 2016-10-23 17:16:01.0
Homepage: null
Size: 12
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
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:
ogram command arg1 arg2
kes `server.command("arg1", "arg2")`
ogram command -a beep -b boop
kes `server.command({ a: "beep", b: "boob" })'
ogram command arg1 arg2 -a beep -b boop
kes `server.command("arg1", "arg2", { a: "beep", b: "boob" })'
ogram command -a beep -b boop arg1 arg2
kes `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.
ho '{"a":"beep","b":"boop"}' | program command
kes `server.command({ a: "beep", b: "boob" })'
Usage-calls are the help which is output when a command fails, or when help is requested. They are used in the following situations:
TypeError
, UsageError
, BadParamError
, or BadArgError
, does a usage call for that command.-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.
zerr = require('zerr')
MissingArgError = zerr('BadArg', '"%" is required')
BadTypeError = zerr('BadArg', '"%" must be a valid %')
manifest = {
age: 'sync',
oami: 'sync',
ng: 'async'
api = {}
uxrpc(null, manifest)(api) is called
usage = function (cmd) {
itch (cmd) {
case 'whoami':
return 'whoami. get your profile info.'
case 'ping':
return 'ping {target} [-n times]. send `n` pings to `target`, defaults to 1'
turn [
'myexample usage:'
' - ' + api.usage('whoami'),
' - ' + api.usage('ping')
join('\n')
whoami = function() { return 'bob, obviously' }
ping = function(target, opts, cb) {
(!target) return cb(MissingArgError('target'))
(!isAddress(target)) return cb(BadTypeError('target', 'address'))
r n = 1
(opts && opts.n) {
n = +opts.n
if (isNaN(n)) return cb(BadTypeError('n', 'number'))
...
Here's how a session would behave with this server:
example
ample usage:
hoami. get your profile info.
ing {target} [-n times]. send `n` pings to `target. defaults to 1
example whoami -h
mi. get your profile info.
example ping -h
{target} [-n times]. send `n` pings to `target. defaults to 1
example whoami
obviously
example ping 127.0.0.1
example ping 1123123123
ArgError: "target" must be a valid address]
{target} [-n times]. send `n` pings to `target. defaults to 1
example ping 127.0.0.1 -n foobar
ArgError: "n" must be a valid number]
{target} [-n times]. send `n` pings to `target. defaults to 1