feat(ArgumentParser): Add TryCreate returning Result<_, exn>#306
Open
dimension-zero wants to merge 3 commits into
Open
feat(ArgumentParser): Add TryCreate returning Result<_, exn>#306dimension-zero wants to merge 3 commits into
dimension-zero wants to merge 3 commits into
Conversation
* ArgumentParser.fs: New static method TryCreate<'Template> with the same optional-parameter shape as Create. Wraps the constructor in try/with, mapping any schema-validation exception (or other construction failure) to Result.Error. Pure addition; Create is unchanged. Hosts that previously had to try/with around 'let parser = ArgumentParser.Create<Args>()' at module init can now switch to the Result path without changing call shape.
4 new tests: * TryCreate returns Ok for a valid template; the wrapped parser exposes HelpFlags as usual. * TryCreate returns Error for a template with two cases that share a CustomCommandLine identifier (caught by checkUnionArgInfo's conflicting-CLI-identifier check); the error message mentions the conflicting name or 'conflicting'. * TryCreate Ok parser matches Create<T>() in HelpFlags and case count. * TryCreate Error path does not throw — the whole point of the API. Net suite size on this branch: 112 -> 116.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(ArgumentParser): Add TryCreate returning Result<_, exn>
same optional-parameter shape as Create. Wraps the constructor in
try/with, mapping any schema-validation exception (or other
construction failure) to Result.Error.
Pure addition; Create is unchanged. Hosts that previously had to
try/with around 'let parser = ArgumentParser.Create()' at module
init can now switch to the Result path without changing call shape.
test(TryCreate): Add coverage for Ok / Error paths
4 new tests:
HelpFlags as usual.
CustomCommandLine identifier (caught by checkUnionArgInfo's
conflicting-CLI-identifier check); the error message mentions the
conflicting name or 'conflicting'.
Net suite size on this branch: 112 -> 116.