feat(ParseConfig): Add record + Parse(config) overload (additive)#307
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an additive ParseConfig record and a new Parse(config: ParseConfig) overload on ArgumentParser<'Template> that simply forwards to the existing optional-argument Parse overload. Intended for callers that prefer to assemble parse parameters as data (e.g. layering host defaults over user overrides) rather than through many optional method arguments. Existing overloads are untouched, so this is non-breaking.
Changes:
- Introduce public
ParseConfigrecord (withDefaultmatching historicalParsedefaults) in theArgunamespace. - Add
ArgumentParser<'Template>.Parse(config: ParseConfig)overload that delegates to the existing optional-argumentParse. - Add a new
ParseConfigTests.fscovering defaults, explicit inputs, parity with the optional overload,IgnoreMissing,IgnoreUnrecognized, andConfigurationReader.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Argu/ArgumentParser.fs | Adds ParseConfig record + Default and a new Parse(config) overload forwarding to existing Parse. |
| tests/Argu.Tests/ParseConfigTests.fs | New xUnit/Unquote tests for the ParseConfig record and Parse(config) overload. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* ArgumentParser.fs: Introduce public ParseConfig record carrying Inputs, ConfigurationReader, IgnoreMissing, IgnoreUnrecognized, RaiseOnUsage. Provide ParseConfig.Default reproducing the historical Parse(...) defaults. * New Parse(config: ParseConfig) overload delegates to the existing Parse(?inputs, ?configurationReader, ...) implementation. All current overloads remain untouched, so existing callers see no shape change. Useful when hosts want to layer configuration programmatically (e.g. merging container-provided defaults with user overrides) rather than juggling many optional method arguments.
6 new tests: * ParseConfig.Default holds the historical defaults (None inputs, None reader, false IgnoreMissing/IgnoreUnrecognized, true RaiseOnUsage). * Parse(config with explicit inputs) parses those inputs. * Parse(config) matches Parse(?inputs, ...) for the same shape. * IgnoreMissing=true skips the mandatory check on empty inputs. * IgnoreUnrecognized=true gathers unknown args into UnrecognizedCliParams. * ConfigurationReader provided via config sources AppSettings entries. A separate non-mandatory schema is used for the AppSettings test because Argu's missing-mandatory check fires from CLI parsing even when AppSettings provides a value (existing behaviour, not introduced by PR 19). Net suite size on this branch: 112 -> 118. # Conflicts: # tests/Argu.Tests/Argu.Tests.fsproj
4e33ca2 to
38f5d32
Compare
38f5d32 to
99f1f25
Compare
|
@dimension-zero See #317 (comment) #317 (comment) I feel it'd be a net win to take ParseConfig out of the picture now (i.e. revert this PR) and focus instead on the extensions layering and rationalizing the top level ParseCommand vs ParseWith(argv, configReader) vs ParseWithAsync(argv, asyncConfigReader) split All going well, that clarifies matters to the extent that this becomes entirely superfluous |
feat(ParseConfig): Add record + Parse(config) overload (additive)
Inputs, ConfigurationReader, IgnoreMissing, IgnoreUnrecognized,
RaiseOnUsage. Provide ParseConfig.Default reproducing the historical
Parse(...) defaults.
Parse(?inputs, ?configurationReader, ...) implementation. All current
overloads remain untouched, so existing callers see no shape change.
Useful when hosts want to layer configuration programmatically (e.g.
merging container-provided defaults with user overrides) rather than
juggling many optional method arguments.
test(ParseConfig): Add coverage for ParseConfig record + Parse(config)
6 new tests:
reader, false IgnoreMissing/IgnoreUnrecognized, true RaiseOnUsage).
A separate non-mandatory schema is used for the AppSettings test because
Argu's missing-mandatory check fires from CLI parsing even when AppSettings
provides a value (existing behaviour, not introduced by PR 19).
Net suite size on this branch: 112 -> 118.