Skip to content

feat(ArgumentParser): Add TryCreate returning Result<_, exn>#306

Open
dimension-zero wants to merge 3 commits into
fsprojects:masterfrom
dimension-zero:pr/18-trycreate-result-factories
Open

feat(ArgumentParser): Add TryCreate returning Result<_, exn>#306
dimension-zero wants to merge 3 commits into
fsprojects:masterfrom
dimension-zero:pr/18-trycreate-result-factories

Conversation

@dimension-zero
Copy link
Copy Markdown
Contributor

feat(ArgumentParser): Add TryCreate returning Result<_, exn>

  • 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()' 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:

  • 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() 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.


dimension-zero and others added 3 commits May 23, 2026 18:00
* 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.
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.

1 participant