From 2def058077f75b7a328760fd8b8e188d8a2fcd92 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Sun, 4 Jun 2017 18:36:33 +0200 Subject: [PATCH] Do not falback to default IP for device but allow global definition using environment variable. --- README.md | 2 ++ cli.js | 23 ++++++++++++++++------- package.json | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 590d543..7b1293b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ npm i -g status-dev-cli * `--ip ` to specify your device's IP address. If you don't know your device's IP address, just run `status-dev-cli scan`. The IP should be provided for every command you try to execute (except `scan`, of course) +Device IP can also be provided using the `STATUS_DEVICE_IP` environment variable (e.g. `STATUS_DEVICE_IP=192.168.0.2 status-dev-cli list`) + #### 1. Scanning the network ***status-dev-cli 3.2.0+, Status 0.9.8+*** diff --git a/cli.js b/cli.js index 0f6a389..09b3537 100755 --- a/cli.js +++ b/cli.js @@ -11,10 +11,19 @@ const mdns = require('mdns'); const pkgJson = require(__dirname + '/package.json'); const client = new watchman.Client(); -const defaultIp = "localhost"; +const defaultIp = process.env.STATUS_DEVICE_IP; const statusDebugServerPort = 5561; const StatusDev = require('./index.js'); +function createStatusDev() { + const ip = cli.ip || defaultIp; + if (ip == null) { + console.error(chalk.red("You have provide your device IP using --ip.")); + process.exit(1); + } + return new StatusDev({ip: ip}); +} + function fromAscii(str) { var hex = ""; for(var i = 0; i < str.length; i++) { @@ -104,7 +113,7 @@ function printServerProblem() { cli.command("add [contact]") .description("Adds a contact") .action(function (contact) { - var statusDev = new StatusDev({ip: cli.ip || defaultIp}); + var statusDev = createStatusDev(); var contactData = getPackageData(contact); if (contactData) { statusDev.addContact(contactData, function(err, body) { @@ -122,7 +131,7 @@ cli.command("add [contact]") cli.command("remove [contactIdentity]") .description("Removes a contact") .action(function (contactIdentity) { - var statusDev = new StatusDev({ip: cli.ip || defaultIp}); + var statusDev = createStatusDev(); var contact = null; if (contactIdentity) { @@ -145,7 +154,7 @@ cli.command("remove [contactIdentity]") cli.command("refresh [contactIdentity]") .description("Refreshes a debuggable contact") .action(function (contactIdentity) { - var statusDev = new StatusDev({ip: cli.ip || defaultIp}); + var statusDev = createStatusDev(); var contact = null; if (contactIdentity) { @@ -168,7 +177,7 @@ cli.command("refresh [contactIdentity]") cli.command("switch-node ") .description("Switches the current RPC node") .action(function (url) { - var statusDev = new StatusDev({ip: cli.ip || defaultIp}); + var statusDev = createStatusDev(); statusDev.switchNode(url, function(err, body) { if (err) { printMan(); @@ -183,7 +192,7 @@ cli.command("switch-node ") cli.command("list") .description("Displays all debuggable DApps and bots") .action(function () { - var statusDev = new StatusDev({ip: cli.ip || defaultIp}); + var statusDev = createStatusDev(); statusDev.listDApps(function (err, body) { if (err) { printMan(); @@ -208,7 +217,7 @@ cli.command("list") cli.command("log ") .description("Returns log for a specified DApp or bot") .action(function (contactIdentity) { - var statusDev = new StatusDev({ip: cli.ip || defaultIp}); + var statusDev = createStatusDev(); statusDev.getLog(contactIdentity, function (err, body) { if (err) { printMan(); diff --git a/package.json b/package.json index 914e7e2..4890b67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "status-dev-cli", - "version": "3.2.8", + "version": "3.2.9", "description": "CLI for Status", "main": "index.js", "bin": {