From 3f95e786bc769c9d94a3039c32150b62f7e2eb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=27rysiek=27=20Wo=C5=BAniak?= Date: Sat, 10 Dec 2022 22:01:28 +0000 Subject: [PATCH] =?UTF-8?q?cli:=20bugfix=20=E2=80=94=20gracefully=20handli?= =?UTF-8?q?ng=20lack=20of=20"arguments"=20key=20in=20action=20object=20(re?= =?UTF-8?q?f.=20#66)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/lrcli.js | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/cli/lrcli.js b/cli/lrcli.js index 665d345..761c95c 100755 --- a/cli/lrcli.js +++ b/cli/lrcli.js @@ -46,31 +46,35 @@ Options: let printPluginActionUsage = (action, action_name) => { + // initialize let options = "" - for (const opt in action.arguments) { - if (opt == '_') { - continue - } - options += `\n --${opt}` - if ("default" in action.arguments[opt]) { - options += ` (default: ${action.arguments[opt].default})` - } - options += `\n ${action.arguments[opt].description}` - options += `\n` - } + let positional = "" + let positional_desc = "" - let positional = '' - let positional_desc = '' - if ('_' in action.arguments) { - if ('name' in action.arguments._) { - positional = ` <${action.arguments._.name}...>` - } else { - positional = ' ' + if ("arguments" in action) { + for (const opt in action.arguments) { + if (opt == '_') { + continue + } + options += `\n --${opt}` + if ("default" in action.arguments[opt]) { + options += ` (default: ${action.arguments[opt].default})` + } + options += `\n ${action.arguments[opt].description}` + options += `\n` } - positional_desc = ` + + if ('_' in action.arguments) { + if ('name' in action.arguments._) { + positional = ` <${action.arguments._.name}...>` + } else { + positional = ' ' + } + positional_desc = ` - ${positional} - ${action.arguments._.description}` + ${positional} + ${action.arguments._.description}` + } } let usage = ` ${action_name}${ (options != "") ? " [options...]" : "" }${positional} @@ -215,7 +219,8 @@ if (['--help', '-h'].includes(parsed_args._[2])) { var parsed_plugin_args = parsePluginActionArgs( // removing the plugin name and the method name parsed_args._.slice(2), - plugin.actions[action].arguments + // empty object in case arguments key does not exist + plugin.actions[action].arguments || {} ) //console.log(parsed_plugin_args)