extended test script, updated docs v5, added USB docs
This commit is contained in:
+24
-1
@@ -3,6 +3,7 @@ const si = require('../lib/index');
|
||||
function test(f) {
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
// console.log(f);
|
||||
if (f === 'a') { si.audio().then(data => resolve({ data, title: 'Audio' }) )}
|
||||
else if (f === 'b') { si.bios().then(data => resolve({ data, title: 'BIOS' })) }
|
||||
else if (f === 'B') { si.baseboard().then(data => resolve({ data, title: 'Baseboard' })) }
|
||||
@@ -37,12 +38,34 @@ function test(f) {
|
||||
else if (f === 'w') { si.wifiNetworks().then(data => resolve({ data, title: 'WIFI Networks' })) }
|
||||
else if (f === 'y') { si.battery().then(data => resolve({ data, title: 'Battery' })) }
|
||||
else if (f === 'z') { si.users().then(data => resolve({ data, title: 'Users' })) }
|
||||
else resolve();
|
||||
else if (f === '1') { si.networkInterfaceDefault().then(data => resolve({ data, title: 'NET Iface Default' })) }
|
||||
else if (f === '2') { si.networkGatewayDefault().then(data => resolve({ data, title: 'NET Gateway Default' })) }
|
||||
else if (f === '3') { si.networkInterfaces().then(data => resolve({ data, title: 'NET Interfaces' })) }
|
||||
else if (f === '4') { si.networkStats().then(data => resolve({ data, title: 'NET Stats' })) }
|
||||
else if (f === '5') { si.networkConnections().then(data => resolve({ data, title: 'NET Connections' })) }
|
||||
else if (f === '6') { si.dockerInfo().then(data => resolve({ data, title: 'Docker Info' })) }
|
||||
else if (f === '7') { si.dockerContainers(true).then(data => resolve({ data, title: 'Docker Containers' })) }
|
||||
else if (f === '8') { si.dockerContainerStats('1').then(data => resolve({ data, title: 'Docker Cont Stats' })) }
|
||||
else if (f === '9') { si.dockerContainerProcesses('1').then(data => resolve({ data, title: 'Docker Cont Processes' })) }
|
||||
else if (f === '0') { si.dockerAll().then(data => resolve({ data, title: 'Docker All' })) }
|
||||
else if (f === '+') { si.getStaticData().then(data => resolve({ data, title: 'All Static Data' })) }
|
||||
else if (f === '-') { si.getDynamicData('apache2, postgres').then(data => resolve({ data, title: 'All Dynamic Data' })) }
|
||||
else if (f === '#') { si.getAllData('apache2, postgres').then(data => resolve({ data, title: 'All Data' })) }
|
||||
else if (f === ',') {
|
||||
const valueObject = {
|
||||
cpu: '*',
|
||||
osInfo: 'platform, release',
|
||||
system: 'model, manufacturer'
|
||||
}
|
||||
si.get(valueObject).then(data => resolve({ data, title: 'Get Object' }))
|
||||
}
|
||||
else resolve('no_key');
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const key = process.argv[2];
|
||||
// console.log(process.argv)
|
||||
|
||||
// console.log(process.argv);
|
||||
|
||||
|
||||
+59
-18
@@ -2,6 +2,9 @@ const readline = require('readline');
|
||||
const util = require('util');
|
||||
const { exec } = require('child_process');
|
||||
|
||||
let waiting = false;
|
||||
let timer;
|
||||
|
||||
function printMenu() {
|
||||
console.log('');
|
||||
console.log('-----------------------------------------------------------------------------------------------------------------------------------');
|
||||
@@ -29,28 +32,66 @@ function EnableUserInput() {
|
||||
// }
|
||||
function noop() { }
|
||||
|
||||
process.stdin.on('keypress', (key, data) => {
|
||||
// console.log(data);
|
||||
if (data.name === 'q' && !data.shift) {
|
||||
// shut down
|
||||
process.exit()
|
||||
}
|
||||
function dot() {
|
||||
process.stdout.write('.');
|
||||
}
|
||||
|
||||
exec('node si.js ' + key, (error, stdout) => {
|
||||
try {
|
||||
if (stdout.toString()) {
|
||||
data = JSON.parse(stdout.toString());
|
||||
function startDots() {
|
||||
dot();
|
||||
timer = setInterval(() => {
|
||||
dot();
|
||||
}, 500)
|
||||
}
|
||||
|
||||
function stopDots() {
|
||||
clearInterval(timer);
|
||||
}
|
||||
|
||||
function printTitle(title) {
|
||||
title = '||' + (' ' + title + ' ').substr(0, 36) + '||'
|
||||
console.log('========================================');
|
||||
console.log(title);
|
||||
console.log('========================================');
|
||||
|
||||
}
|
||||
|
||||
process.stdin.on('keypress', (key, data) => {
|
||||
// console.log(data);
|
||||
if (data.name === 'q' && !data.shift) {
|
||||
// shut down
|
||||
process.exit()
|
||||
}
|
||||
|
||||
if (!waiting) {
|
||||
waiting = true;
|
||||
startDots();
|
||||
exec(`node si.js '${key}'`, {timeout: 30000}, (error, stdout) => {
|
||||
waiting = false;
|
||||
stopDots();
|
||||
if (error && error.signal) {
|
||||
console.log();
|
||||
console.log('===============================');
|
||||
console.log('[ ' + data.title + ' ]');
|
||||
console.log('===============================');
|
||||
console.log(util.inspect(data.data, { colors: true, depth: 4 }));
|
||||
printMenu();
|
||||
console.log('TIMEOUT!');
|
||||
} else {
|
||||
try {
|
||||
if (stdout.toString().startsWith('"no_key')) {
|
||||
console.log()
|
||||
console.log('menu item not found - select valid menu item')
|
||||
} else if (stdout.toString()) {
|
||||
data = JSON.parse(stdout.toString());
|
||||
console.log();
|
||||
console.log();
|
||||
printTitle(data.title);
|
||||
console.log(util.inspect(data.data, { colors: true, depth: 4 }));
|
||||
printMenu();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log();
|
||||
console.log('Key: ' + key);
|
||||
console.log('ERROR - UNSUPPORTET');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
noop();
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
printMenu();
|
||||
|
||||
Reference in New Issue
Block a user