runtime-shell
Version:
Some useful shell commands for runtime.js
32 lines (28 loc) • 878 B
JavaScript
/*
'use strict';
const shellUtil = require('../util');
const dns = require('dns');
const url = require('url');
module.exports = function(runtime) {
runtime.shell.setCommand('ping', function(args, env, cb) {
var argarr = shellUtil.parse(args);
argarr[0] = argarr[0] || 'http://www.google.com/';
dns.lookup(url.parse(argarr[0]).host, function(err, address, iptype) {
if (err) {
env.stdio.writeError('error: cannot load', argarr[0] + '\n');
env.stdio.writeError(err);
return cb(1);
}
const times = parseInt(argarr[1]) || 1;
for (var i = 0; i < times; i++) {
http.get(argarr[0], function(res) {
env.stdio.writeLine('statcode', res.statusCode, 'from', url.parse(argarr[0]).host, '(' + address + ')');
if (i == times) {
cb(0);
}
});
}
});
});
};
*/