Skip to content

Commit

Permalink
fixup! Add support for mutually exclusive arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmisiak committed Nov 12, 2021
1 parent a037502 commit 955aadb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/command-parser/commandParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export enum CommandType {
}

const initParser = (parser: ArgumentParser | ArgumentGroup, config: any): void => {
const isMutuallyExclusiveGroup = (str: string) => str.startsWith('_mutually-exclusive-group')
const isOneOfGroupRequired = (str: string) => str.endsWith('-required')
const MUTUALLY_EXCLUSIVE_GROUP_KEY = '_mutually-exclusive-group'
const isMutuallyExclusiveGroup = (str: string) => str.startsWith(MUTUALLY_EXCLUSIVE_GROUP_KEY)
const isOneOfGroupRequired = (str: string) => str.endsWith(`${MUTUALLY_EXCLUSIVE_GROUP_KEY}-required`)
const isCommand = (str: string) => !str.startsWith('--') && !isMutuallyExclusiveGroup(str)
const commandType = (parent: string, current: string) => (parent ? `${parent}.${current}` : current)

Expand Down
11 changes: 7 additions & 4 deletions src/command-parser/parserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ const opCertSigningArgs = {
}

// If you want to define a group of mutually exclusive CLI arguments (eg. see address.show below),
// bundle these arguments under a key prefixed with '_mutually-exclusive-group'. Furthermore, if you
// want argparse to ensure that one of the arguments is present, add '-required' suffix.
// bundle these arguments under a key prefixed with '_mutually-exclusive-group'. Several such groups
// may be present next to each other, an optional key suffix can be added to enable this (JS objects
// cannot have duplicate keys).
// If you want argparse to ensure that one of the arguments is present, use
// '_mutually-exclusive-group-required' prefix instead.

// based on cardano-cli interface
// https://docs.cardano.org/projects/cardano-node/en/latest/reference/cardano-node-cli-reference.html
Expand Down Expand Up @@ -165,7 +168,7 @@ export const parserConfig = {
'key-gen': keyGenArgs,

'show': { // hw-specific subpath
'_mutually-exclusive-group-payment-required': {
'_mutually-exclusive-group-required-payment': {
'--payment-path': {
type: (path: string) => parseBIP32Path(path),
dest: 'paymentPath',
Expand All @@ -177,7 +180,7 @@ export const parserConfig = {
help: 'Payment derivation script hash in hex format.',
},
},
'_mutually-exclusive-group-staking-required': {
'_mutually-exclusive-group-required-staking': {
'--staking-path': {
type: (path: string) => parseBIP32Path(path),
dest: 'stakingPath',
Expand Down

0 comments on commit 955aadb

Please sign in to comment.