diff options
author | Florian Dold <florian@dold.me> | 2023-02-15 23:32:42 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-02-16 02:50:29 +0100 |
commit | 825d2c4352022e7397854b2bd9ba7d3589873c07 (patch) | |
tree | d23530bf8408367439e6b3820ea0c4269bfeb39a /packages/taler-util/src/clk.ts | |
parent | cb2f4c21d85707abb0221cbf2a859a98836b2d44 (diff) | |
download | wallet-core-825d2c4352022e7397854b2bd9ba7d3589873c07.tar.xz |
make wallet-cli runnable under qtart
Diffstat (limited to 'packages/taler-util/src/clk.ts')
-rw-r--r-- | packages/taler-util/src/clk.ts | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/packages/taler-util/src/clk.ts b/packages/taler-util/src/clk.ts index e99ebf733..7bcd19b04 100644 --- a/packages/taler-util/src/clk.ts +++ b/packages/taler-util/src/clk.ts @@ -17,10 +17,12 @@ /** * Imports. */ -import process from "process"; -import path from "path"; -import readline from "readline"; -import { devNull } from "os"; +import { + processExit, + processArgv, + readlinePrompt, + pathBasename, +} from "#compat-impl"; export namespace clk { class Converter<T> {} @@ -359,13 +361,13 @@ export namespace clk { console.error( `error: unknown option '--${r.key}' for ${currentName}`, ); - process.exit(-1); + processExit(-1); throw Error("not reached"); } if (d.isFlag) { if (r.value !== undefined) { console.error(`error: flag '--${r.key}' does not take a value`); - process.exit(-1); + processExit(-1); throw Error("not reached"); } storeFlag(d, true); @@ -373,7 +375,7 @@ export namespace clk { if (r.value === undefined) { if (i === unparsedArgs.length - 1) { console.error(`error: option '--${r.key}' needs an argument`); - process.exit(-1); + processExit(-1); throw Error("not reached"); } storeOption(d, unparsedArgs[i + 1]); @@ -391,7 +393,7 @@ export namespace clk { const opt = this.shortOptions[chr]; if (!opt) { console.error(`error: option '-${chr}' not known`); - process.exit(-1); + processExit(-1); } if (opt.isFlag) { storeFlag(opt, true); @@ -399,7 +401,7 @@ export namespace clk { if (si == optShort.length - 1) { if (i === unparsedArgs.length - 1) { console.error(`error: option '-${chr}' needs an argument`); - process.exit(-1); + processExit(-1); throw Error("not reached"); } else { storeOption(opt, unparsedArgs[i + 1]); @@ -418,7 +420,7 @@ export namespace clk { const subcmd = this.subcommandMap[argVal]; if (!subcmd) { console.error(`error: unknown command '${argVal}'`); - process.exit(-1); + processExit(-1); throw Error("not reached"); } foundSubcommand = subcmd.commandGroup; @@ -427,7 +429,7 @@ export namespace clk { const d = this.arguments[posArgIndex]; if (!d) { console.error(`error: too many arguments for ${currentName}`); - process.exit(-1); + processExit(-1); throw Error("not reached"); } myArgs[d.name] = unparsedArgs[i]; @@ -437,7 +439,7 @@ export namespace clk { if (parsedArgs[this.argKey].help) { this.printHelp(progname, parents); - process.exit(0); + processExit(0); throw Error("not reached"); } @@ -450,7 +452,7 @@ export namespace clk { console.error( `error: missing positional argument '${d.name}' for ${currentName}`, ); - process.exit(-1); + processExit(-1); throw Error("not reached"); } } @@ -464,7 +466,7 @@ export namespace clk { } else { const name = option.flagspec.join(","); console.error(`error: missing option '${name}'`); - process.exit(-1); + processExit(-1); throw Error("not reached"); } } @@ -492,16 +494,16 @@ export namespace clk { } catch (e) { console.error(`An error occurred while running ${currentName}`); console.error(e); - process.exit(1); + processExit(1); } Promise.resolve(r).catch((e) => { console.error(`An error occurred while running ${currentName}`); console.error(e); - process.exit(1); + processExit(1); }); } else { this.printHelp(progname, parents); - process.exit(-1); + processExit(-1); throw Error("not reached"); } } @@ -524,15 +526,15 @@ export namespace clk { if (cmdlineArgs) { args = cmdlineArgs; } else { - args = process.argv.slice(1); + args = processArgv().slice(1); } if (args.length < 1) { console.error( "Error while parsing command line arguments: not enough arguments", ); - process.exit(-1); + processExit(-1); } - const progname = path.basename(args[0]); + const progname = pathBasename(args[0]); const rest = args.slice(1); this.mainCommand.run(progname, [], rest, {}); @@ -622,15 +624,6 @@ export namespace clk { } export function prompt(question: string): Promise<string> { - const stdinReadline = readline.createInterface({ - input: process.stdin, - output: process.stdout, - }); - return new Promise<string>((resolve, reject) => { - stdinReadline.question(question, (res) => { - resolve(res); - stdinReadline.close(); - }); - }); + return readlinePrompt(question); } } |