BLOCKS CLI
Install
npm install -g pubnub-cli
Help
node pubnub-cli -h
Usage
Usage: pubnub-cli [OPTIONS] <command> [ARGS] Options: -b, --block NUMBER Block ID -k, --key NUMBER Subscribe Key ID -f, --file PATH A block file -m, --email STRING Email -n, --insert INSERT Insert Mode. Create new blocks and skip prompts. -a, --account NUMBER Account ID -p, --password STRING Password --debug Show debug information -h, --help Display help and usage details Commands: init, log, login, logout, pull, push, start, stop, watch, test
- Init - Download the remote PubNub function and event handlers locally
- Log - Log the event handler output to console
- Login - Authorize with PubNub and write session to disk
- Logout - Remove local session from disk
- Pull - Download remote event handlers and overwrite file
- Push - Upload remote event handlers and overwrite
- Start - Start the remote PubNub Function
- Stop - Stop the remote PubNub Funciton
- Watch - Watch the local directory and push event handlers when changes are detected
- Test - Run event handler unit tests
Login
Authorizes this computer with PubNub API.
Input:
pubnub-cli login
Output:
pubnub-cli login? PubNub Email: ian@pubnub.com? PubNub Password: *************Logging In... Done!OK: ---------------------------------------OK: Logged In!OK: Deluxe!OK: ---------------------------------------
Creates a file ~/.pubnub-cli
with PubNub session properties:
This file is used for every request thereafter.
Init
Writes a block.json
file. Use selects key and block (or creates a new block). Block information is pulled from server and persisted into file.
Note the -f
specifies the directory of the future block.json
file. See "Pull" below for more info on block.json
.
Input:
pubnub-cli init
Output:
INFO: Reading session from /Users/ian/.pubnub-cliOK: Working as ian@meetjennings.comOK: Which app are you working on?? Select a key eon-demosOK: Which block are you working on?? Select a block Email Sendgrid BlockOK: ---------------------------------------OK: New block.json written to disk.OK: Deluxe!OK: ---------------------------------------OK: Use this handy command next time:OK: node pubnub-cli init -b 853 -k 145183
Pull
Pulls block information from server and writes to block.json
.
Input
pubnub-cli pull
Output
INFO: Reading session from /Users/ian/.pubnub-cliOK: Working as ian@meetjennings.comOK: Working on block Email Sendgrid BlockOK: ---------------------------------------OK: Local block.json updated with remote data.OK: Deluxe!OK: ---------------------------------------OK: Use this handy command next time:OK: node pubnub-cli pull -b 853 -k 145183
Block.json looks like:
The properties _key_id
and _id
represent the key id and block id respectively. These should not be modified.
Push
Updates server with information provided in block.json. Upload code by specifying a file
within the event handler object. See below for example.
Input
pubnub-cli push
Output
OK: Working as ian@meetjennings.comOK: Working on block Email Sendgrid BlockOK: ---------------------------------------OK: Block pushedOK: Deluxe!OK: ---------------------------------------OK: Use this handy command next time:OK: node pubnub-cli push -b 853 -k 145183
Sample block.json for uploading event handlers directly:
Start
Starts running a block.
Input
pubnub-cli start
Output
OK: Working as ian@meetjennings.comOK: Working on block Email Sendgrid BlockOK: Sending start commandStarting Block...OK: ---------------------------------------OK: Block startedOK: Deluxe!OK: ---------------------------------------
Stop
Stops a running block.
Input
pubnub-cli stop
Output
NFO: Reading session from /Users/ian/.pubnub-cliOK: Working as ian@meetjennings.comOK: Working on block Email Sendgrid BlockOK: ---------------------------------------OK: Block stoppedOK: Deluxe!OK: ---------------------------------------
Test
Runs unit tests for the event handlers with pubnub-functions-mock
package in the local environment.
pubnub-cli test
Output
OK: Working with prod environment at https://admin.pubnub.comOK: Working on block CICD Example #eventhandler ✓ creates event handler of type Function 1 passing (9ms) #endpoint ✓ creates endpoint event handler of type Function 1 passing (9ms) OK: ---------------------------------------OK: Unit tests completed.OK: Deluxe!OK: ---------------------------------------