From ea84616822d51afcbd574404e93e0599ee53ff2a Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 3 Dec 2016 11:26:26 +0100 Subject: [PATCH] cli: clean args check code, print all errors, pass the whole argv object cli: prevent -n and -g simultaneously --- app/main/settings.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/main/settings.js b/app/main/settings.js index 398222ef..7b8bc921 100644 --- a/app/main/settings.js +++ b/app/main/settings.js @@ -29,8 +29,18 @@ var options = { } }, 'd':{alias:'debug',type:'boolean',describe:'log received osc messages in the console'}, - 'n':{alias:'no-gui',type:'boolean',describe:'disable default gui'}, - 'g':{alias:'gui-only',type:'string',describe:'app server\'s url. If true, local port (--port) is used'}, + 'n':{alias:'no-gui',type:'boolean',describe:'disable default gui', + check: (n,argv)=>{ + return (!argv.g) ? + true : 'no-gui and gui-only can\'s be enbabled simulataneously' + } + }, + 'g':{alias:'gui-only',type:'string',describe:'app server\'s url. If true, local port (--port) is used', + check: (g,argv)=>{ + return (!argv.n) ? + true : 'no-gui and gui-only can\'s be enbabled simulataneously' + } + }, 't':{alias:'theme',type:'array',describe:'theme name or path (mutliple values allowed)'}, 'e':{alias:'examples',type:'boolean',describe:'list examples instead of recent sessions'} } @@ -40,16 +50,16 @@ var argv = require('yargs') .help('help').usage(`\nUsage:\n $0 [options]`).alias('h', 'help') .options(options) .check((argv)=>{ + var err = [] for (key in options) { - var ok = true if (options[key].check && argv[key] != undefined) { - ok = options[key].check(argv[key]) - } - if (ok!==true) { - throw ok + var c = options[key].check(argv[key],argv) + if (c!==true) { + err.push(`-${key}: ${c}`) + } } } - return true + return err.length ? err.join('\n') : true }) .strict() .version().alias('v','version')