kopia lustrzana https://gitlab.com/rysiekpl/libresilient
cli: describing plugin actions along with arguments and options
rodzic
3ecf637167
commit
49b494f858
53
cli/lrcli.js
53
cli/lrcli.js
|
@ -43,6 +43,44 @@ Options:
|
||||||
console.log(usage)
|
console.log(usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let printPluginActionUsage = (action, action_name) => {
|
||||||
|
|
||||||
|
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 = ''
|
||||||
|
if ('_' in action.arguments) {
|
||||||
|
if ('name' in action.arguments._) {
|
||||||
|
positional = ` <${action.arguments._.name}...>`
|
||||||
|
} else {
|
||||||
|
positional = ' <item...>'
|
||||||
|
}
|
||||||
|
positional_desc = `
|
||||||
|
|
||||||
|
${positional}
|
||||||
|
${action.arguments._.description}`
|
||||||
|
}
|
||||||
|
|
||||||
|
let usage = ` ${action_name}${ (options != "") ? " [options...]" : "" }${positional}
|
||||||
|
${action.description}${positional_desc}
|
||||||
|
${options}`
|
||||||
|
|
||||||
|
console.log(usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let printpluginUsage = (plugin) => {
|
let printpluginUsage = (plugin) => {
|
||||||
let usage = `
|
let usage = `
|
||||||
CLI plugin:
|
CLI plugin:
|
||||||
|
@ -64,6 +102,10 @@ Actions and Action Options:
|
||||||
`
|
`
|
||||||
|
|
||||||
console.log(usage)
|
console.log(usage)
|
||||||
|
|
||||||
|
for (const action in plugin.actions) {
|
||||||
|
printPluginActionUsage(plugin.actions[action], action)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(parsed_args)
|
//console.log(parsed_args)
|
||||||
|
@ -156,20 +198,25 @@ if (parsed_args._.length == 1) {
|
||||||
|
|
||||||
let action = parsed_args._[1]
|
let action = parsed_args._[1]
|
||||||
if ( ! (action in plugin.actions) ) {
|
if ( ! (action in plugin.actions) ) {
|
||||||
var exit_code = 4
|
var exit_code = 0
|
||||||
if (!['--help', '-h'].includes(action)) {
|
if (!['--help', '-h'].includes(action)) {
|
||||||
console.log(`\n*** Action not supported: ${action} ***`)
|
console.log(`\n*** Action not supported: ${action} ***`)
|
||||||
exit_code = 0
|
exit_code = 4
|
||||||
}
|
}
|
||||||
printpluginUsage(plugin)
|
printpluginUsage(plugin)
|
||||||
Deno.exit(exit_code)
|
Deno.exit(exit_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (['--help', '-h'].includes(parsed_args._[2])) {
|
||||||
|
printpluginUsage(plugin)
|
||||||
|
Deno.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
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
|
plugin.actions[action].arguments
|
||||||
)
|
)
|
||||||
|
|
||||||
//console.log(parsed_plugin_args)
|
//console.log(parsed_plugin_args)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue