kopia lustrzana https://gitlab.com/rysiekpl/libresilient
cli: bugfix — gracefully handling lack of "arguments" key in action object (ref. #66)
rodzic
035d5d8c4b
commit
3f95e786bc
49
cli/lrcli.js
49
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 = ' <item...>'
|
||||
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 = ' <item...>'
|
||||
}
|
||||
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)
|
||||
|
|
Ładowanie…
Reference in New Issue