Skip to content

Commit 4c01b0e

Browse files
committed
feat(cli): case insensitive choices
This makes commands that have enumerated choices - such as `swap_client` which accepts either `Lnd` or `Connext` - case insensitive in regards to those choices. Previously a value of `lnd` in the example above would throw an error due to an invalid value.
1 parent 98d6ca9 commit 4c01b0e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: lib/cli/commands/addcurrency.ts

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export const builder = (argv: Argv) => argv
1616
description: 'the payment channel network client for swaps',
1717
type: 'string',
1818
choices: ['Lnd', 'Connext'],
19+
coerce: (swapClientStr: string) => {
20+
const swapClientLower = swapClientStr.toLowerCase();
21+
return swapClientLower.charAt(0).toUpperCase() + swapClientLower.slice(1);
22+
},
1923
})
2024
.option('decimal_places', {
2125
description: 'the places to the right of the decimal point of the smallest subunit (e.g. satoshi)',
@@ -33,6 +37,7 @@ export const handler = async (argv: Arguments<any>) => {
3337
if (isNaN(argv.decimal_places) || argv.decimal_places >= 100 || argv.decimal_places < 0) {
3438
throw 'decimal_places must be a number between 0 and 100';
3539
}
40+
3641
const request = new Currency();
3742
request.setCurrency(argv.currency.toUpperCase());
3843
request.setSwapClient(Number(SwapClientType[argv.swap_client]));

Diff for: lib/cli/commands/listorders.ts

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export const builder = (argv: Argv) => argv
9191
describe: 'whether to include own, peer or both orders',
9292
type: 'string',
9393
choices: ['Both', 'Own', 'Peer'],
94+
coerce: (ownerStr: string) => {
95+
const ownerLower = ownerStr.toLowerCase();
96+
return ownerLower.charAt(0).toUpperCase() + ownerLower.slice(1);
97+
},
9498
default: 'Both',
9599
})
96100
.option('limit', {

0 commit comments

Comments
 (0)