1.2.2 • Published 9 years ago
swarm-cli v1.2.2
Swarm command-line client
A simple filesystem-backed Swarm client. Works more like a version control system: saves data to plain files, pulls/pushes updates from/to the server. Works offline, reconnects automatically.
Usage
swarm [options] dbdir/Options
-- dbdir: replica's home path (default: .)-C --connect urlconnect to a server, init a replica- ws://1.2.3.4:5/dbid WebSocket
- wss://1.2.3.4:5/dbid WebSocket (secure)
- tcp://1.2.3.4:5/dbid TCP
-u --update type/idupdate (default: all the objects)-c --create type-g --get type/id-r --recur depthrecursive retrieval (default: depth 1)
-p --put type/idcommit a manually edited JSON object-o --op type/idfeed an op (args or stdin must contain op name, value)-n --nameop name-v --valueop value
-e --edit type/idedit a JSON state, put when done (uses $EDITOR)-l --loglist the log of pending ops (those not acked by the server)-m --muteignore connect/listen options in the db-R --replrun REPL-E --execexecute script(s), e.g. --exec init.js -e run.js-T --tracetrace incoming/outgoing ops
Examples
# install swarm client (see swarm-server on how to run a server)
$ npm i -g swarm-cli
# connect to the server, init the client
$ swarm -C tcp://gritzko:password@localhost:31415/testdb
$ cd testdb/
# create an object
$ swarm --create LWWObject
/LWWObject#1GDBdW+Rgritzko01
# see the outer JSON state of the object
$ cat LWWObject/1GDBdW+Rgritzko01.json
{"_id":"1GDBdW+Rgritzko01","_version":"1GDBdW+Rgritzko01"}
# see the inner CRDT state (data+metadata)
$ cat LWWObject/.1GDBdW+Rgritzko01.~
# make a change to the object, see some client-server chit-chat
$ swarm --trace -o LWWObject/1GDBdW+Rgritzko01 -n FieldName -v FieldValue
...
< /LWWObject#1GDBdW+Rgritzko01!1GDBdk+Rgritzko01.FieldName FieldValue
> /LWWObject#1GDBdW+Rgritzko01!1GDBdk+Rgritzko01.FieldName FieldValue
...
# launch REPL, play with the JavaScript API
$ swarm --repl
≶ o = swarm.get('1GDBdW+Rgritzko01', obj => console.log(obj.get('FieldName')));
FieldValue
≶ o.set('FieldName', 'another value');
...