diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9e56101..8a4ecfc 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -6,7 +6,6 @@ * Fix [misrendering of usage when parameter description blank](https://github.com/fsprojects/Argu/issues/173) [#323](https://github.com/fsprojects/Argu/pull/323) [@DominikL1999](https://github.com/DominikL1999) * Add `Separator("=", orSpace = true)` and `Separator "="` attribute syntax to replace `Obsolete`d `EqualsAssignment`, `ColonAssignment`, `CustomAssignment`, `EqualsAssignmentOrSpaced`, `ColonAssignmentOrSpaced` and `CustomAssignmentOrSpaced` [#315](https://github.com/fsprojects/Argu/pull/315) [@dimension-zero](https://github.com/dimension-zero) * Add `Argu.Samples.Introspect` sample [#298](https://github.com/fsprojects/Argu/pull/298) [@dimension-zero](https://github.com/dimension-zero) -* Add `ArgumentParser.Parse(ParseConfig)` [#307](https://github.com/fsprojects/Argu/pull/307) [@dimension-zero](https://github.com/dimension-zero) * Add `ArgumentParser.PrintUsage(..., ?UsageStrings)` for localization support [#303](https://github.com/fsprojects/Argu/pull/303) [@dimension-zero](https://github.com/dimension-zero) * Add AOT annotations [#314](https://github.com/fsprojects/Argu/pull/314) [@dimension-zero](https://github.com/dimension-zero) * Add `SourceGenerator.ArguGenerate` marker [#318](https://github.com/fsprojects/Argu/pull/318) [@dimension-zero](https://github.com/dimension-zero) diff --git a/src/Argu/ArgumentParser.fs b/src/Argu/ArgumentParser.fs index 9da0f5e..d328b87 100644 --- a/src/Argu/ArgumentParser.fs +++ b/src/Argu/ArgumentParser.fs @@ -5,35 +5,6 @@ open System.Diagnostics.CodeAnalysis open Argu.UnionArgInfo -/// Configuration record for . -/// Each field carries the same meaning as the matching optional parameter on -/// the existing Parse overload. Use -/// as a starting point and override only the fields you care about. -[] -type ParseConfig = - { - /// The command line input. None takes the inputs from System.Environment. - Inputs : string [] option - /// Configuration reader used to source AppSettings-style arguments. - /// None uses the AppSettings configuration of the current process. - ConfigurationReader : IConfigurationReader option - /// Ignore errors caused by the Mandatory attribute. - IgnoreMissing : bool - /// Ignore CLI arguments that do not match the schema. - IgnoreUnrecognized : bool - /// Treat '--help' parameters as parse errors. - RaiseOnUsage : bool - } - /// Default parse configuration, matching the historical Parse(...) defaults: - /// inputs and configurationReader inherited from the environment, do not ignore - /// missing or unrecognized arguments, and raise on '--help'. - static member Default : ParseConfig = - { Inputs = None - ConfigurationReader = None - IgnoreMissing = false - IgnoreUnrecognized = false - RaiseOnUsage = true } - module internal TrimMessages = [] let aot = @@ -201,19 +172,6 @@ and [] with ParserExn (errorCode, msg) -> errorHandler.Exit (msg, errorCode) - /// Parse both command line args and supplied configuration reader, using - /// a record. Useful when callers want to construct - /// the parameter set programmatically (e.g. layering host defaults over user - /// overrides) without juggling many optional method arguments. - /// The parse configuration. See ParseConfig.Default. - member self.Parse (config : ParseConfig) : ParseResults<'Template> = - self.Parse( - ?inputs = config.Inputs, - ?configurationReader = config.ConfigurationReader, - ignoreMissing = config.IgnoreMissing, - ignoreUnrecognized = config.IgnoreUnrecognized, - raiseOnUsage = config.RaiseOnUsage) - /// Parse both command line args and supplied configuration reader. /// Results are merged with command line args overriding configuration parameters. /// The command line input. Taken from System.Environment if not specified. diff --git a/tests/Argu.Tests/Argu.Tests.fsproj b/tests/Argu.Tests/Argu.Tests.fsproj index d0c2522..a7369f9 100644 --- a/tests/Argu.Tests/Argu.Tests.fsproj +++ b/tests/Argu.Tests/Argu.Tests.fsproj @@ -9,7 +9,6 @@ - diff --git a/tests/Argu.Tests/ParseConfigTests.fs b/tests/Argu.Tests/ParseConfigTests.fs deleted file mode 100644 index 68edf22..0000000 --- a/tests/Argu.Tests/ParseConfigTests.fs +++ /dev/null @@ -1,85 +0,0 @@ -module Argu.Tests.ParseConfigTests - -open System.Collections.Generic -open Swensen.Unquote -open Xunit - -open Argu - -type Args = - | [] Port of int - | Verbose - | Tag of string - interface IArgParserTemplate with - member this.Usage = - match this with - | Port _ -> "port" - | Verbose -> "verbose" - | Tag _ -> "tag" - -let private parser () = ArgumentParser.Create() -[] -let ``ParseConfig.Default holds historical defaults`` () = - let d = ParseConfig.Default - test <@ d.Inputs = None @> - test <@ d.ConfigurationReader = None @> - test <@ d.IgnoreMissing = false @> - test <@ d.IgnoreUnrecognized = false @> - test <@ d.RaiseOnUsage = true @> - -[] -let ``Parse(config with explicit inputs) parses those inputs`` () = - let p = parser () - let argv = [| "--port"; "8080"; "--verbose" |] - let cfg = { ParseConfig.Default with Inputs = Some argv ; RaiseOnUsage = false } - let results = p.Parse(cfg) - test <@ results.GetResult(Port) = 8080 @> - test <@ results.Contains(Verbose) @> - -[] -let ``Parse(config) matches Parse(?inputs, ...) for the same parameters`` () = - let p = parser () - let argv = [| "--port"; "1234"; "--tag"; "v1" |] - let viaConfig = - let cfg = { ParseConfig.Default with Inputs = Some argv ; RaiseOnUsage = false } - p.Parse(cfg) - let viaOptional = p.Parse(inputs = argv, raiseOnUsage = false) - test <@ viaConfig.GetResult(Port) = viaOptional.GetResult(Port) @> - test <@ viaConfig.GetResult(Tag) = viaOptional.GetResult(Tag) @> - -[] -let ``Parse(config with IgnoreMissing=true) skips mandatory check`` () = - let p = parser () - let cfg = { ParseConfig.Default with Inputs = Some [||] ; IgnoreMissing = true } - let results = p.Parse(cfg) - test <@ results.TryGetResult(Port) = None @> - -[] -let ``Parse(config with IgnoreUnrecognized=true) collects unknown args`` () = - let p = parser () - let cfg = - { ParseConfig.Default with - Inputs = Some [| "--port"; "1"; "--bogus" |] - IgnoreUnrecognized = true - RaiseOnUsage = false } - let results = p.Parse(cfg) - test <@ results.UnrecognizedCliParams |> List.contains "--bogus" @> - -/// Argu's missing-mandatory check fires from the CLI even when AppSettings provides a value (pre-existing behavior), -/// so the AppSettings round-trip test uses a non-mandatory schema. -type AppSettingsArgs = - | TagKey of string - interface IArgParserTemplate with member this.Usage = "tag" - -[] -let ``Parse(config with ConfigurationReader) sources AppSettings`` () = - let p = ArgumentParser.Create() - let dict = Dictionary() - dict["tagkey"] <- "v1" - let reader = ConfigurationReader.FromDictionary dict - let cfg = - { ParseConfig.Default with - Inputs = Some [||] - ConfigurationReader = Some reader } - let results = p.Parse(cfg) - test <@ results.GetResult(TagKey) = "v1" @>