From 8d4a7d6103032a85c81240d9fb0de32dd44ec435 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 16 Oct 2022 20:15:55 +0200 Subject: wallet-core: CLI improvements, ToS fetching fixes --- packages/taler-wallet-cli/src/index.ts | 109 ++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 49 deletions(-) (limited to 'packages/taler-wallet-cli/src') diff --git a/packages/taler-wallet-cli/src/index.ts b/packages/taler-wallet-cli/src/index.ts index 249198e3c..b50e11883 100644 --- a/packages/taler-wallet-cli/src/index.ts +++ b/packages/taler-wallet-cli/src/index.ts @@ -314,48 +314,42 @@ walletCli logger.info("finished handling API request"); }); -walletCli - .subcommand("", "pending", { help: "Show pending operations." }) - .action(async (args) => { - await withWallet(args, async (wallet) => { - const pending = await wallet.client.call( - WalletApiOperation.GetPendingOperations, - {}, - ); - console.log(JSON.stringify(pending, undefined, 2)); - }); - }); - -walletCli - .subcommand("transactions", "transactions", { help: "Show transactions." }) +const transactionsCli = walletCli + .subcommand("transactions", "transactions", { help: "Manage transactions." }) .maybeOption("currency", ["--currency"], clk.STRING) - .maybeOption("search", ["--search"], clk.STRING) - .action(async (args) => { - await withWallet(args, async (wallet) => { - const pending = await wallet.client.call( - WalletApiOperation.GetTransactions, - { - currency: args.transactions.currency, - search: args.transactions.search, - }, - ); - console.log(JSON.stringify(pending, undefined, 2)); - }); + .maybeOption("search", ["--search"], clk.STRING); + +// Default action +transactionsCli.action(async (args) => { + await withWallet(args, async (wallet) => { + const pending = await wallet.client.call( + WalletApiOperation.GetTransactions, + { + currency: args.transactions.currency, + search: args.transactions.search, + }, + ); + console.log(JSON.stringify(pending, undefined, 2)); }); +}); -walletCli - .subcommand("runPendingOpt", "run-pending", { - help: "Run pending operations.", +transactionsCli + .subcommand("deleteTransaction", "delete", { + help: "Permanently delete a transaction from the transaction list.", + }) + .requiredArgument("transactionId", clk.STRING, { + help: "Identifier of the transaction to delete", }) - .flag("forceNow", ["-f", "--force-now"]) .action(async (args) => { await withWallet(args, async (wallet) => { - await wallet.ws.runPending(args.runPendingOpt.forceNow); + await wallet.client.call(WalletApiOperation.DeleteTransaction, { + transactionId: args.deleteTransaction.transactionId, + }); }); }); -walletCli - .subcommand("retryTransaction", "retry-transaction", { +transactionsCli + .subcommand("retryTransaction", "retry", { help: "Retry a transaction.", }) .requiredArgument("transactionId", clk.STRING) @@ -387,21 +381,6 @@ walletCli }); }); -walletCli - .subcommand("deleteTransaction", "delete-transaction", { - help: "Permanently delete a transaction from the transaction list.", - }) - .requiredArgument("transactionId", clk.STRING, { - help: "Identifier of the transaction to delete", - }) - .action(async (args) => { - await withWallet(args, async (wallet) => { - await wallet.client.call(WalletApiOperation.DeleteTransaction, { - transactionId: args.deleteTransaction.transactionId, - }); - }); - }); - walletCli .subcommand("withdraw", "withdraw", { help: "Withdraw with a taler://withdraw/ URI", @@ -604,17 +583,26 @@ exchangesCli exchangesCli .subcommand("exchangesTosCmd", "tos", { - help: "Show terms of service.", + help: "Show/request terms of service.", }) .requiredArgument("url", clk.STRING, { help: "Base URL of the exchange.", }) + .maybeOption("contentTypes", ["--content-type"], clk.STRING) .action(async (args) => { + let acceptedFormat: string[] | undefined = undefined; + if (args.exchangesTosCmd.contentTypes) { + const split = args.exchangesTosCmd.contentTypes + .split(",") + .map((x) => x.trim()); + acceptedFormat = split; + } await withWallet(args, async (wallet) => { const tosResult = await wallet.client.call( WalletApiOperation.GetExchangeTos, { exchangeBaseUrl: args.exchangesTosCmd.url, + acceptedFormat, }, ); console.log(JSON.stringify(tosResult, undefined, 2)); @@ -764,6 +752,29 @@ advancedCli await withWallet(args, async () => {}); }); +advancedCli + .subcommand("runPendingOpt", "run-pending", { + help: "Run pending operations.", + }) + .flag("forceNow", ["-f", "--force-now"]) + .action(async (args) => { + await withWallet(args, async (wallet) => { + await wallet.ws.runPending(args.runPendingOpt.forceNow); + }); + }); + +advancedCli + .subcommand("", "pending", { help: "Show pending operations." }) + .action(async (args) => { + await withWallet(args, async (wallet) => { + const pending = await wallet.client.call( + WalletApiOperation.GetPendingOperations, + {}, + ); + console.log(JSON.stringify(pending, undefined, 2)); + }); + }); + advancedCli .subcommand("bench1", "bench1", { help: "Run the 'bench1' benchmark", -- cgit v1.2.3