Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mutually exclusive arguments #109

Merged
merged 2 commits into from
Nov 18, 2021

Conversation

davidmisiak
Copy link
Collaborator

Fixes #106.

The _mutually-exclusive-group key feels somewhat hacky, but I think it could be acceptable, because it keeps the parseConfig.ts readability and doesn't require something needlessly complicated in commandParser.ts.

@davidmisiak davidmisiak requested a review from KubqoA October 29, 2021 15:51
@KubqoA KubqoA force-pushed the dm/102-refactor-signing-validation branch from 6d42857 to 9758b94 Compare November 2, 2021 14:38
@KubqoA KubqoA force-pushed the dm/106-mutually-exclusive-arguments branch from eb6b8d5 to d4fd03f Compare November 2, 2021 14:38
@davidmisiak davidmisiak requested a review from janmazak November 11, 2021 21:34
Copy link
Collaborator

@janmazak janmazak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I approve.

src/command-parser/parserConfig.ts Outdated Show resolved Hide resolved
src/command-parser/parserConfig.ts Show resolved Hide resolved
@davidmisiak davidmisiak force-pushed the dm/102-refactor-signing-validation branch from 9758b94 to 35fc2a6 Compare November 12, 2021 21:35
@davidmisiak davidmisiak force-pushed the dm/106-mutually-exclusive-arguments branch from d4fd03f to 955aadb Compare November 12, 2021 22:25
const initParser = (parser: ArgumentParser | ArgumentGroup, config: any): void => {
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`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be at the start of the string? But we are using endsWith.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have some unit tests for command parser? This definitely deserves a test, one for optional, one for required mutually exclusive group (maybe having two groups, too).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be at the start of the string? But we are using endsWith.

Thanks for noticing! That was really a stupid mistake. (I remember testing it manually, but perhaps I forgot to rerun yarn build-js or something.)

Don't we have some unit tests for command parser? This definitely deserves a test, one for optional, one for required mutually exclusive group (maybe having two groups, too).

We do, but they seem more like integration tests for command parsing - the tests are verifying whether the entire input from command line matches expected ParsedArguments after parsing, not whether individual parsers work as expected. I don't think developing an entire new command parser testing approach is worth it (considering that the CLI API and implementation doesn't change that much).

However, I noticed that address show test is missing, so I added at least that. I tried to add a test for both payment path and script hash present (which violates the mutual exclusiveness), but it turns out that when argparse founds a problem it terminates the process instead of throwing an error. There is an option exit_on_error which can be set to false, but I couldn't get it working with mutually exclusive groups correctly. Again, I'm not sure it's worth the effort and added complexity in code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to test individual parsers.

At this point, I would leave this as an open github issue. We can return to it someday, perhaps after argparse will start working as expected :) Just write down a concise summary of why you couldn't make it work in the issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, issue added #111

@davidmisiak davidmisiak force-pushed the dm/106-mutually-exclusive-arguments branch from 955aadb to bb13a5b Compare November 17, 2021 09:35
Copy link
Collaborator

@janmazak janmazak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not try to run it.

@davidmisiak davidmisiak force-pushed the dm/102-refactor-signing-validation branch from aad00db to 81ea3f7 Compare November 18, 2021 15:52
@davidmisiak davidmisiak force-pushed the dm/106-mutually-exclusive-arguments branch from bb13a5b to a5d6a30 Compare November 18, 2021 16:01
@davidmisiak davidmisiak changed the base branch from dm/102-refactor-signing-validation to ja/multisig November 18, 2021 16:01
@davidmisiak davidmisiak merged commit 726dd5a into ja/multisig Nov 18, 2021
@gabrielKerekes gabrielKerekes deleted the dm/106-mutually-exclusive-arguments branch November 22, 2021 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants