Merge pull request #9 from jeluard/master

Make ip parameter mandatory
This commit is contained in:
Alexander Pantyuhov 2017-06-05 11:12:10 +03:00 committed by GitHub
commit a1e629c00d
4 changed files with 39 additions and 46 deletions

View File

@ -20,6 +20,8 @@ npm i -g status-dev-cli
* `--ip <device-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+***

26
cli.js
View File

@ -1,20 +1,26 @@
#!/usr/bin/env node
const cli = require("commander");
const child = require('child_process');
const watchman = require('fb-watchman');
const fs = require('fs');
const path = require('path');
const request = require('request');
const chalk = require('chalk');
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 +110,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 +128,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 +151,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 +174,7 @@ cli.command("refresh [contactIdentity]")
cli.command("switch-node <url>")
.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 +189,7 @@ cli.command("switch-node <url>")
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 +214,7 @@ cli.command("list")
cli.command("log <contactIdentity>")
.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();

View File

@ -14,73 +14,58 @@ var StatusDev = function(options) {
this.url = "http://" + options.ip + ":5561";
};
StatusDev.prototype.addContact = function(contactData, cb) {
request({
url: this.url + "/add-dapp",
function requestOptions(url, body) {
return {
url: url,
method: "POST",
timeout: 3000,
json: true,
body: { encoded: fromAscii(contactData) }
}, function (error, response, body) {
body: body};
}
StatusDev.prototype.addContact = function(contactData, cb) {
request(requestOptions(this.url + "/add-dapp", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.removeContact = function(contactData, cb) {
request({
url: this.url + "/remove-dapp",
method: "POST",
json: true,
body: { encoded: fromAscii(contactData) }
}, function (error, response, body) {
request(requestOptions(this.url + "/remove-dapp", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.refreshContact = function(contactData, cb) {
request({
url: this.url + "/dapp-changed",
method: "POST",
json: true,
body: { encoded: fromAscii(contactData) }
}, function (error, response, body) {
request(requestOptions(this.url + "/dapp-changed", { encoded: fromAscii(contactData) })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.switchNode = function(rpcUrl, cb) {
request({
url: this.url + "/switch-node",
method: "POST",
json: true,
body: {encoded: fromAscii(JSON.stringify({"url": rpcUrl}))}
}, function (error, response, body) {
request(requestOptions(this.url + "/switch-node", {encoded: fromAscii(JSON.stringify({"url": rpcUrl}))})
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.listDApps = function(cb) {
request({
url: this.url + "/list",
json: true,
method: "POST",
body: {}
}, function (error, response, body) {
request(requestOptions(this.url + "/list", {})
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});
};
StatusDev.prototype.getLog = function(identity, cb) {
request({
url: this.url + "/log",
method: "POST",
json: true,
body: { identity: identity }
}, function (error, response, body) {
request(requestOptions(this.url + "/log", { identity: identity })
, function (error, response, body) {
if (cb === undefined) { return }
cb(error, body);
});

View File

@ -1,6 +1,6 @@
{
"name": "status-dev-cli",
"version": "3.2.8",
"version": "3.2.9",
"description": "CLI for Status",
"main": "index.js",
"bin": {