fixed cli method '-ls / --list'

This commit is contained in:
Daniel Sommer 2022-03-03 21:18:07 +01:00
parent 91a50073da
commit 20efca9234
4 changed files with 15 additions and 10 deletions

View file

@ -4,6 +4,7 @@ const cli = require('./libs/cli.js');
const server = require('./libs/server.js');
const controller = require('./libs/controller.js');
const packageJSON = require('./package');
const constants = require('./libs/constants.js');
const INTERRUPTS = ['SIGINT', 'SIGTERM'];
@ -23,7 +24,7 @@ async function main() {
logger.initialize();
logger.info(global.appName + ' ' + global.appVersion + ' starting...');
if (await cli.handleArguments()) {
exit();
util.exit();
}
await controller.findBlinkstick();
logger.info(await server.start());
@ -32,7 +33,10 @@ async function main() {
async function setGlobalConfig() {
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) {
config = process.argv[index + 1];
}

View file

@ -7,9 +7,11 @@ async function handleArguments() {
for (let index = 0; index < process.argv.length; index++) {
switch (process.argv[index]) {
case constants.ARG_CONFIG:
case constants.ARG_CONFIG_SHORT:
continue;
case constants.ARG_GET_SERIALS:
logger.info('blinksticks: ' + JSON.stringify(await controller.findBlinkstick(constants.ALL)));
case constants.ARG_LIST:
case constants.ARG_LIST_SHORT:
logger.info('blinksticks: ' + JSON.stringify(await controller.findBlinkstick(constants.ALL, true)));
handled++;
break;
}

View file

@ -9,7 +9,9 @@ module.exports = {
MODE_POWEROFF: 'poweroff',
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,
DELAY_DEFAULT: require('../config.json').api.post.delay.default || 500

View file

@ -11,7 +11,7 @@ let blinksticks;
async function findBlinkstick(index, ignoreFilter) {
if (!global.config.blinkstick?.cache || blinksticks === undefined) {
blinksticks = blinkstick.findAll();
if (global.config.blinkstick?.serials?.length > 0) {
if (!ignoreFilter && global.config.blinkstick?.serials?.length > 0) {
blinksticks = blinksticks.filter((blinkstick) => {
return global.config.blinkstick.serials.includes(blinkstick.serial);
});
@ -26,10 +26,7 @@ async function findBlinkstick(index, ignoreFilter) {
if (index === undefined) {
index = 0;
} else if (index !== constants.ALL) {
index = parseInt(index);
}
if (isNaN(index)) {
index = 0;
index = parseInt(index) || 0;
}
if (index > blinksticks.length - 1) {
throw new Error('there is no blinkstick for index \'' + index + '\'');