kopia lustrzana https://gitlab.com/rysiekpl/libresilient
cli: preparing lrcli.js for tests, part 2 (ref. #66)
rodzic
1711334e74
commit
4b46a58809
24
cli/lrcli.js
24
cli/lrcli.js
|
@ -151,10 +151,10 @@ let parsePluginActionArgs = (args, argdef) => {
|
|||
// we *always* pass arguments to plugins as arrays of strings,
|
||||
// even if we only got one value
|
||||
|
||||
let main = async () => {
|
||||
let main = async (args) => {
|
||||
|
||||
var parsed_args = parse(
|
||||
Deno.args,
|
||||
args,
|
||||
{
|
||||
default: {
|
||||
h: false,
|
||||
|
@ -177,7 +177,11 @@ let main = async () => {
|
|||
// no unknown parsed args? that means we have no plugin specified
|
||||
if (parsed_args._.length == 0) {
|
||||
console.log(getUsage())
|
||||
return 1
|
||||
if (parsed_args.help) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// try loading the plugin
|
||||
|
@ -195,9 +199,15 @@ let main = async () => {
|
|||
// but no info from the user what to do with it
|
||||
// → print plugin usage and exit
|
||||
if (parsed_args._.length == 1) {
|
||||
console.log('\n*** No action specified for plugin ***')
|
||||
if (!parsed_args.help) {
|
||||
console.log('\n*** No action specified for plugin ***')
|
||||
}
|
||||
console.log(getPluginUsage(plugin))
|
||||
return 3
|
||||
if (parsed_args.help) {
|
||||
return 0;
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
let action = parsed_args._[1]
|
||||
|
@ -231,9 +241,11 @@ let main = async () => {
|
|||
await plugin.actions[action].run(...parsed_plugin_args)
|
||||
)
|
||||
)
|
||||
return 0
|
||||
} catch (e) {
|
||||
console.log(`\n*** ${e} ***`)
|
||||
console.log(getPluginUsage(plugin))
|
||||
return 5
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,5 +256,5 @@ export {
|
|||
|
||||
// run only if we're the main module
|
||||
if (import.meta.main) {
|
||||
Deno.exit(await main())
|
||||
Deno.exit(await main(Deno.args))
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue