diff --git a/docs/content/tutorial.fsx b/docs/content/tutorial.fsx index acc06a85..291e7991 100644 --- a/docs/content/tutorial.fsx +++ b/docs/content/tutorial.fsx @@ -286,8 +286,8 @@ with and GitArgs = | Version | [] Verbose - | [] Clean of ParseResult - | [] Commit of ParseResult + | [] Clean of ParseResults + | [] Commit of ParseResults with interface IArgParserTemplate with member this.Usage = diff --git a/src/Argu/Argu.fsproj b/src/Argu/Argu.fsproj index ba0dc289..152013e6 100644 --- a/src/Argu/Argu.fsproj +++ b/src/Argu/Argu.fsproj @@ -70,7 +70,7 @@ - + diff --git a/src/Argu/ArgumentParser.fs b/src/Argu/ArgumentParser.fs index c12a0483..b2f88a4b 100644 --- a/src/Argu/ArgumentParser.fs +++ b/src/Argu/ArgumentParser.fs @@ -112,7 +112,7 @@ and [] /// Ignore errors caused by the Mandatory attribute. Defaults to false. /// Ignore CLI arguments that do not match the schema. Defaults to false. /// Treat '--help' parameters as parse errors. Defaults to true. - member __.ParseCommandLine (?inputs : string [], ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResult<'Template> = + member __.ParseCommandLine (?inputs : string [], ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResults<'Template> = let ignoreMissing = defaultArg ignoreMissing false let ignoreUnrecognized = defaultArg ignoreUnrecognized false let raiseOnUsage = defaultArg raiseOnUsage true @@ -123,21 +123,21 @@ and [] let ignoreMissing = (cliResults.IsUsageRequested && not raiseOnUsage) || ignoreMissing let results = postProcessResults argInfo ignoreMissing None (Some cliResults) - new ParseResult<'Template>(argInfo, results, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler) + new ParseResults<'Template>(argInfo, results, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler) with ParserExn (errorCode, msg) -> errorHandler.Exit (msg, errorCode) /// Parse arguments using specified configuration reader only. This defaults to the AppSettings configuration of the current process. /// Configuration reader used to source the arguments. Defaults to the AppSettings configuration of the current process. /// Ignore errors caused by the Mandatory attribute. Defaults to false. - member __.ParseConfiguration (configurationReader : IConfigurationReader, ?ignoreMissing : bool) : ParseResult<'Template> = + member __.ParseConfiguration (configurationReader : IConfigurationReader, ?ignoreMissing : bool) : ParseResults<'Template> = let ignoreMissing = defaultArg ignoreMissing false try let appSettingsResults = parseKeyValueConfig configurationReader argInfo let results = postProcessResults argInfo ignoreMissing (Some appSettingsResults) None - new ParseResult<'Template>(argInfo, results, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler) + new ParseResults<'Template>(argInfo, results, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler) with ParserExn (errorCode, msg) -> errorHandler.Exit (msg, errorCode) @@ -148,7 +148,7 @@ and [] /// Ignore errors caused by the Mandatory attribute. Defaults to false. /// Ignore CLI arguments that do not match the schema. Defaults to false. /// Treat '--help' parameters as parse errors. Defaults to false. - member __.Parse (?inputs : string [], ?configurationReader : IConfigurationReader, ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResult<'Template> = + member __.Parse (?inputs : string [], ?configurationReader : IConfigurationReader, ?ignoreMissing, ?ignoreUnrecognized, ?raiseOnUsage) : ParseResults<'Template> = let ignoreMissing = defaultArg ignoreMissing false let ignoreUnrecognized = defaultArg ignoreUnrecognized false let raiseOnUsage = defaultArg raiseOnUsage true @@ -160,7 +160,7 @@ and [] let cliResults = parseCommandLine argInfo _programName helpTextMessage _usageStringCharacterWidth errorHandler raiseOnUsage ignoreUnrecognized inputs let results = postProcessResults argInfo ignoreMissing (Some appSettingsResults) (Some cliResults) - new ParseResult<'Template>(argInfo, results, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler) + new ParseResults<'Template>(argInfo, results, _programName, helpTextMessage, _usageStringCharacterWidth, errorHandler) with ParserExn (errorCode, msg) -> errorHandler.Exit (msg, errorCode) @@ -168,7 +168,7 @@ and [] /// If specified, parse AppSettings configuration from given xml configuration file. /// Ignore errors caused by the Mandatory attribute. Defaults to false. [] - member __.ParseAppSettings (?xmlConfigurationFile : string, ?ignoreMissing : bool) : ParseResult<'Template> = + member __.ParseAppSettings (?xmlConfigurationFile : string, ?ignoreMissing : bool) : ParseResults<'Template> = let configurationReader = match xmlConfigurationFile with | None -> ConfigurationReader.FromAppSettings() @@ -185,17 +185,17 @@ and [] __.ParseConfiguration(configurationReader, ?ignoreMissing = ignoreMissing) /// - /// Converts a sequence of template argument inputs into a ParseResult instance + /// Converts a sequence of template argument inputs into a ParseResults instance /// /// Argument input sequence. - member __.ToParseResult (inputs : seq<'Template>) : ParseResult<'Template> = + member __.ToParseResults (inputs : seq<'Template>) : ParseResults<'Template> = mkParseResultFromValues argInfo errorHandler _usageStringCharacterWidth _programName helpTextMessage inputs /// /// Gets a subparser associated with specific subcommand instance /// /// Expression providing the subcommand union constructor. - member __.GetSubCommandParser (expr : Expr -> 'Template>) : ArgumentParser<'SubTemplate> = + member __.GetSubCommandParser (expr : Expr -> 'Template>) : ArgumentParser<'SubTemplate> = let uci = expr2Uci expr let case = argInfo.Cases.[uci.Tag] match case.ParameterInfo with @@ -276,15 +276,15 @@ type ArgumentParser with [] module ArgumentParserUtils = - type ParseResult<'Template when 'Template :> IArgParserTemplate> with + type ParseResults<'Template when 'Template :> IArgParserTemplate> with /// Gets the parser instance corresponding to the parse result member r.Parser = new ArgumentParser<'Template>(r.ArgInfo, r.ProgramName, r.Description, r.CharacterWidth, r.ErrorHandler) - /// converts a sequence of inputs to a ParseResult instance - let toParseResults (inputs : seq<'Template>) : ParseResult<'Template> = - ArgumentParser.Create<'Template>().ToParseResult(inputs) + /// converts a sequence of inputs to a ParseResults instance + let toParseResults (inputs : seq<'Template>) : ParseResults<'Template> = + ArgumentParser.Create<'Template>().ToParseResults(inputs) /// gets the F# union tag representation of given argument instance let tagOf (input : 'Template) : int = diff --git a/src/Argu/ParseResult.fs b/src/Argu/ParseResults.fs similarity index 99% rename from src/Argu/ParseResult.fs rename to src/Argu/ParseResults.fs index 38cdd433..540acde9 100644 --- a/src/Argu/ParseResult.fs +++ b/src/Argu/ParseResults.fs @@ -4,7 +4,7 @@ open FSharp.Quotations /// Argument parsing result holder. [] -type ParseResult<'Template when 'Template :> IArgParserTemplate> +type ParseResults<'Template when 'Template :> IArgParserTemplate> internal (argInfo : UnionArgInfo, results : UnionParseResults, programName : string, description : string option, usageStringCharWidth : int, exiter : IExiter) = let mkUsageString message = mkUsageString argInfo programName usageStringCharWidth message |> StringExpr.build diff --git a/src/Argu/Parsers/Cli.fs b/src/Argu/Parsers/Cli.fs index ea3480a3..cd4b93d9 100644 --- a/src/Argu/Parsers/Cli.fs +++ b/src/Argu/Parsers/Cli.fs @@ -306,7 +306,7 @@ let rec private parseCommandLinePartial (state : CliParseState) (argInfo : Union let result = existential.Accept { new ITemplateFunc with member __.Invoke<'Template when 'Template :> IArgParserTemplate> () = - new ParseResult<'Template>(nestedUnion, nestedResults, state.ProgramName, state.Description, state.UsageStringCharWidth, state.Exiter) :> obj } + new ParseResults<'Template>(nestedUnion, nestedResults, state.ProgramName, state.Description, state.UsageStringCharWidth, state.Exiter) :> obj } let result = mkUnionCase caseInfo aggregator.ResultCount ParseSource.CommandLine name [|result|] aggregator.AppendResult result diff --git a/src/Argu/Parsers/Common.fs b/src/Argu/Parsers/Common.fs index 7d52a576..38b2a245 100644 --- a/src/Argu/Parsers/Common.fs +++ b/src/Argu/Parsers/Common.fs @@ -19,7 +19,7 @@ let mkUnionCase (info : UnionCaseArgInfo) index parseSource parsecontext (fields ParseContext = parsecontext } -/// Create a ParseResult<_> instance from a set of template parameters +/// Create a ParseResults<_> instance from a set of template parameters let mkParseResultFromValues (info : UnionArgInfo) (exiter : IExiter) (width : int) (programName : string) (description : string option) (values : seq<'Template>) = @@ -43,7 +43,7 @@ let mkParseResultFromValues (info : UnionArgInfo) (exiter : IExiter) (width : in Cases = agg |> Array.map (fun rs -> rs.ToArray()) } - new ParseResult<'Template>(info, results, programName, description, width, exiter) + new ParseResults<'Template>(info, results, programName, description, width, exiter) /// /// Combines two parse results, AppSettings and CLI, overriding where appropriate. diff --git a/src/Argu/PreCompute.fs b/src/Argu/PreCompute.fs index d14b8f37..800c7fcb 100644 --- a/src/Argu/PreCompute.fs +++ b/src/Argu/PreCompute.fs @@ -43,10 +43,10 @@ let tryExtractUnionParameterLabel (p : PropertyInfo) = if defaultLabelRegex.IsMatch p.Name then None else Some(p.Name.Replace('_',' ')) -let (|NestedParseResult|Optional|List|Other|) (t : Type) = +let (|NestedParseResults|Optional|List|Other|) (t : Type) = if t.IsGenericType then let gt = t.GetGenericTypeDefinition() - if typeof.IsAssignableFrom t then NestedParseResult(t.GetGenericArguments().[0]) + if typeof.IsAssignableFrom t then NestedParseResults(t.GetGenericArguments().[0]) elif gt = typedefof<_ option> then Optional(t.GetGenericArguments().[0]) elif gt = typedefof<_ list> then List(t.GetGenericArguments().[0]) else Other @@ -169,7 +169,7 @@ let getPrimitiveParserByType label (t : Type) = // refine error messaging depending on the input time match t with - | NestedParseResult _ -> arguExn "Nested ParseResult<'T> parameters can only occur as standalone parameters in union constructors." + | NestedParseResults _ -> arguExn "Nested ParseResult<'T> parameters can only occur as standalone parameters in union constructors." | Optional _ -> arguExn "F# Option parameters can only occur as standalone parameters in union constructors." | List _ -> arguExn "F# List parameters can only occur as standalone parameters in union constructors." | _ -> arguExn "template contains unsupported field of type '%O'." t @@ -266,7 +266,7 @@ let rec private preComputeUnionCaseArgInfo (stack : Type list) (helpParam : Help let parsers = match types with - | [|NestedParseResult prt|] -> + | [|NestedParseResults prt|] -> if Option.isSome customAssignmentSeparator then arguExn "CustomAssignment in '%O' not supported in subcommands." uci if isRest then diff --git a/tests/Argu.Tests/Tests.fs b/tests/Argu.Tests/Tests.fs index 0d7988e3..c096a558 100644 --- a/tests/Argu.Tests/Tests.fs +++ b/tests/Argu.Tests/Tests.fs @@ -46,7 +46,7 @@ module ``Argu Tests`` = [] type RequiredSubcommand = | Foo - | [] Sub of ParseResult + | [] Sub of ParseResults with interface IArgParserTemplate with member this.Usage = "required" @@ -80,10 +80,10 @@ module ``Argu Tests`` = | [] A | [] B | [] C - | [] Push of ParseResult - | [] Clean of ParseResult - | [] Required of ParseResult - | [] Unrecognized of ParseResult + | [] Push of ParseResults + | [] Clean of ParseResults + | [] Required of ParseResults + | [] Unrecognized of ParseResults with interface IArgParserTemplate with member a.Usage = @@ -449,25 +449,25 @@ module ``Argu Tests`` = type ConflictingInheritedCliName = | [] Force - | Nested of ParseResult + | Nested of ParseResults with interface IArgParserTemplate with member __.Usage = "not tested" type RecursiveArgument1 = - | Rec1 of ParseResult + | Rec1 of ParseResults with interface IArgParserTemplate with member a.Usage = "foo" and RecursiveArgument2 = - | Rec2 of ParseResult + | Rec2 of ParseResults with interface IArgParserTemplate with member a.Usage = "bar" and RecursiveArgument3 = - | Rec3 of ParseResult + | Rec3 of ParseResults with interface IArgParserTemplate with member a.Usage = "baz" @@ -614,7 +614,7 @@ module ``Argu Tests`` = [] type NestedInherited = - | [] Nested of ParseResult + | [] Nested of ParseResults with interface IArgParserTemplate with member a.Usage = "not tested here" @@ -626,7 +626,7 @@ module ``Argu Tests`` = [] let ``Fail on malformed case constructors`` () = - let result = parser.ToParseResult [] + let result = parser.ToParseResults [] let wrapper = List raises <@ result.Contains <@ fun (y : string) -> Log_Level 42 @> @> raises <@ result.Contains <@ fun (y, x) -> Data(x,y) @> @> diff --git a/tests/Argu.Tests/tests.fsx b/tests/Argu.Tests/tests.fsx index 207c1028..32dcdeab 100644 --- a/tests/Argu.Tests/tests.fsx +++ b/tests/Argu.Tests/tests.fsx @@ -45,8 +45,8 @@ with type GitArgs = | [] Listener of address:string * number:int | Log_Level of level:int - | []Push of options:ParseResult - | []Clean of suboptions:ParseResult + | []Push of options:ParseResults + | []Clean of suboptions:ParseResults | [][]Environment_Variable of key:string * value:string | Ports of tcp_port:int list | Optional of num:int option