cli: bugfix — gracefully handling lack of "arguments" key in action object (ref. #66)

merge-requests/23/head
Michał 'rysiek' Woźniak 2022-12-10 22:01:28 +00:00
rodzic 035d5d8c4b
commit 3f95e786bc
1 zmienionych plików z 27 dodań i 22 usunięć

Wyświetl plik

@ -46,31 +46,35 @@ Options:
let printPluginActionUsage = (action, action_name) => { let printPluginActionUsage = (action, action_name) => {
// initialize
let options = "" let options = ""
for (const opt in action.arguments) { let positional = ""
if (opt == '_') { let positional_desc = ""
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 = '' if ("arguments" in action) {
let positional_desc = '' for (const opt in action.arguments) {
if ('_' in action.arguments) { if (opt == '_') {
if ('name' in action.arguments._) { continue
positional = ` <${action.arguments._.name}...>` }
} else { options += `\n --${opt}`
positional = ' <item...>' 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 = ' <item...>'
}
positional_desc = `
${positional} ${positional}
${action.arguments._.description}` ${action.arguments._.description}`
}
} }
let usage = ` ${action_name}${ (options != "") ? " [options...]" : "" }${positional} let usage = ` ${action_name}${ (options != "") ? " [options...]" : "" }${positional}
@ -215,7 +219,8 @@ if (['--help', '-h'].includes(parsed_args._[2])) {
var parsed_plugin_args = parsePluginActionArgs( var parsed_plugin_args = parsePluginActionArgs(
// removing the plugin name and the method name // removing the plugin name and the method name
parsed_args._.slice(2), 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) //console.log(parsed_plugin_args)