cli: preparing lrcli.js for tests, part 2 (ref. #66)

merge-requests/23/head
Michał 'rysiek' Woźniak 2022-12-11 21:48:12 +00:00
rodzic 1711334e74
commit 4b46a58809
1 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -151,10 +151,10 @@ let parsePluginActionArgs = (args, argdef) => {
// we *always* pass arguments to plugins as arrays of strings, // we *always* pass arguments to plugins as arrays of strings,
// even if we only got one value // even if we only got one value
let main = async () => { let main = async (args) => {
var parsed_args = parse( var parsed_args = parse(
Deno.args, args,
{ {
default: { default: {
h: false, h: false,
@ -177,7 +177,11 @@ let main = async () => {
// no unknown parsed args? that means we have no plugin specified // no unknown parsed args? that means we have no plugin specified
if (parsed_args._.length == 0) { if (parsed_args._.length == 0) {
console.log(getUsage()) console.log(getUsage())
return 1 if (parsed_args.help) {
return 0;
} else {
return 1;
}
} }
// try loading the plugin // try loading the plugin
@ -195,9 +199,15 @@ let main = async () => {
// but no info from the user what to do with it // but no info from the user what to do with it
// → print plugin usage and exit // → print plugin usage and exit
if (parsed_args._.length == 1) { if (parsed_args._.length == 1) {
if (!parsed_args.help) {
console.log('\n*** No action specified for plugin ***') console.log('\n*** No action specified for plugin ***')
}
console.log(getPluginUsage(plugin)) console.log(getPluginUsage(plugin))
return 3 if (parsed_args.help) {
return 0;
} else {
return 3;
}
} }
let action = parsed_args._[1] let action = parsed_args._[1]
@ -231,9 +241,11 @@ let main = async () => {
await plugin.actions[action].run(...parsed_plugin_args) await plugin.actions[action].run(...parsed_plugin_args)
) )
) )
return 0
} catch (e) { } catch (e) {
console.log(`\n*** ${e} ***`) console.log(`\n*** ${e} ***`)
console.log(getPluginUsage(plugin)) console.log(getPluginUsage(plugin))
return 5
} }
} }
@ -244,5 +256,5 @@ export {
// run only if we're the main module // run only if we're the main module
if (import.meta.main) { if (import.meta.main) {
Deno.exit(await main()) Deno.exit(await main(Deno.args))
} }