fixed cli method '-ls / --list'
This commit is contained in:
parent
91a50073da
commit
20efca9234
4 changed files with 15 additions and 10 deletions
|
@ -4,6 +4,7 @@ const cli = require('./libs/cli.js');
|
||||||
const server = require('./libs/server.js');
|
const server = require('./libs/server.js');
|
||||||
const controller = require('./libs/controller.js');
|
const controller = require('./libs/controller.js');
|
||||||
const packageJSON = require('./package');
|
const packageJSON = require('./package');
|
||||||
|
const constants = require('./libs/constants.js');
|
||||||
|
|
||||||
const INTERRUPTS = ['SIGINT', 'SIGTERM'];
|
const INTERRUPTS = ['SIGINT', 'SIGTERM'];
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ async function main() {
|
||||||
logger.initialize();
|
logger.initialize();
|
||||||
logger.info(global.appName + ' ' + global.appVersion + ' starting...');
|
logger.info(global.appName + ' ' + global.appVersion + ' starting...');
|
||||||
if (await cli.handleArguments()) {
|
if (await cli.handleArguments()) {
|
||||||
exit();
|
util.exit();
|
||||||
}
|
}
|
||||||
await controller.findBlinkstick();
|
await controller.findBlinkstick();
|
||||||
logger.info(await server.start());
|
logger.info(await server.start());
|
||||||
|
@ -32,7 +33,10 @@ async function main() {
|
||||||
|
|
||||||
async function setGlobalConfig() {
|
async function setGlobalConfig() {
|
||||||
let config = __dirname + '/config.json';
|
let config = __dirname + '/config.json';
|
||||||
let index = process.argv.indexOf(cli.ARG_CONFIG);
|
let index = process.argv.indexOf(constants.ARG_CONFIG);
|
||||||
|
if (index === -1) {
|
||||||
|
index = process.argv.indexOf(constants.ARG_CONFIG_SHORT);
|
||||||
|
}
|
||||||
if (index >= 0 && process.argv.length >= index + 1) {
|
if (index >= 0 && process.argv.length >= index + 1) {
|
||||||
config = process.argv[index + 1];
|
config = process.argv[index + 1];
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,11 @@ async function handleArguments() {
|
||||||
for (let index = 0; index < process.argv.length; index++) {
|
for (let index = 0; index < process.argv.length; index++) {
|
||||||
switch (process.argv[index]) {
|
switch (process.argv[index]) {
|
||||||
case constants.ARG_CONFIG:
|
case constants.ARG_CONFIG:
|
||||||
|
case constants.ARG_CONFIG_SHORT:
|
||||||
continue;
|
continue;
|
||||||
case constants.ARG_GET_SERIALS:
|
case constants.ARG_LIST:
|
||||||
logger.info('blinksticks: ' + JSON.stringify(await controller.findBlinkstick(constants.ALL)));
|
case constants.ARG_LIST_SHORT:
|
||||||
|
logger.info('blinksticks: ' + JSON.stringify(await controller.findBlinkstick(constants.ALL, true)));
|
||||||
handled++;
|
handled++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ module.exports = {
|
||||||
MODE_POWEROFF: 'poweroff',
|
MODE_POWEROFF: 'poweroff',
|
||||||
|
|
||||||
ARG_CONFIG: '--config',
|
ARG_CONFIG: '--config',
|
||||||
ARG_GET_SERIALS: '--get-blinksticks',
|
ARG_CONFIG_SHORT: '-c',
|
||||||
|
ARG_LIST: '--list',
|
||||||
|
ARG_LIST_SHORT: '-ls',
|
||||||
|
|
||||||
DURATION_DEFAULT: require('../config.json').api.post.duration.default || 1000,
|
DURATION_DEFAULT: require('../config.json').api.post.duration.default || 1000,
|
||||||
DELAY_DEFAULT: require('../config.json').api.post.delay.default || 500
|
DELAY_DEFAULT: require('../config.json').api.post.delay.default || 500
|
||||||
|
|
|
@ -11,7 +11,7 @@ let blinksticks;
|
||||||
async function findBlinkstick(index, ignoreFilter) {
|
async function findBlinkstick(index, ignoreFilter) {
|
||||||
if (!global.config.blinkstick?.cache || blinksticks === undefined) {
|
if (!global.config.blinkstick?.cache || blinksticks === undefined) {
|
||||||
blinksticks = blinkstick.findAll();
|
blinksticks = blinkstick.findAll();
|
||||||
if (global.config.blinkstick?.serials?.length > 0) {
|
if (!ignoreFilter && global.config.blinkstick?.serials?.length > 0) {
|
||||||
blinksticks = blinksticks.filter((blinkstick) => {
|
blinksticks = blinksticks.filter((blinkstick) => {
|
||||||
return global.config.blinkstick.serials.includes(blinkstick.serial);
|
return global.config.blinkstick.serials.includes(blinkstick.serial);
|
||||||
});
|
});
|
||||||
|
@ -26,10 +26,7 @@ async function findBlinkstick(index, ignoreFilter) {
|
||||||
if (index === undefined) {
|
if (index === undefined) {
|
||||||
index = 0;
|
index = 0;
|
||||||
} else if (index !== constants.ALL) {
|
} else if (index !== constants.ALL) {
|
||||||
index = parseInt(index);
|
index = parseInt(index) || 0;
|
||||||
}
|
|
||||||
if (isNaN(index)) {
|
|
||||||
index = 0;
|
|
||||||
}
|
}
|
||||||
if (index > blinksticks.length - 1) {
|
if (index > blinksticks.length - 1) {
|
||||||
throw new Error('there is no blinkstick for index \'' + index + '\'');
|
throw new Error('there is no blinkstick for index \'' + index + '\'');
|
||||||
|
|
Loading…
Reference in a new issue