Skip to content

Commit

Permalink
revert ParseResult --> ParseResults
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Jul 5, 2016
1 parent 0a96083 commit 17e99a7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions docs/content/tutorial.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ with
and GitArgs =
| Version
| [<AltCommandLine("-v")>] Verbose
| [<CliPrefix(CliPrefix.None)>] Clean of ParseResult<CleanArgs>
| [<CliPrefix(CliPrefix.None)>] Commit of ParseResult<CommitArgs>
| [<CliPrefix(CliPrefix.None)>] Clean of ParseResults<CleanArgs>
| [<CliPrefix(CliPrefix.None)>] Commit of ParseResults<CommitArgs>
with
interface IArgParserTemplate with
member this.Usage =
Expand Down
2 changes: 1 addition & 1 deletion src/Argu/Argu.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<Compile Include="UnionArgInfo.fs" />
<Compile Include="PreCompute.fs" />
<Compile Include="UnParsers.fs" />
<Compile Include="ParseResult.fs" />
<Compile Include="ParseResults.fs" />
<Compile Include="Parsers\Common.fs" />
<Compile Include="Parsers\Cli.fs" />
<Compile Include="Parsers\KeyValue.fs" />
Expand Down
28 changes: 14 additions & 14 deletions src/Argu/ArgumentParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// <param name="ignoreMissing">Ignore errors caused by the Mandatory attribute. Defaults to false.</param>
/// <param name="ignoreUnrecognized">Ignore CLI arguments that do not match the schema. Defaults to false.</param>
/// <param name="raiseOnUsage">Treat '--help' parameters as parse errors. Defaults to true.</param>
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
Expand All @@ -123,21 +123,21 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
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)

/// <summary>Parse arguments using specified configuration reader only. This defaults to the AppSettings configuration of the current process.</summary>
/// <param name="configurationReader">Configuration reader used to source the arguments. Defaults to the AppSettings configuration of the current process.</param>
/// <param name="ignoreMissing">Ignore errors caused by the Mandatory attribute. Defaults to false.</param>
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)

Expand All @@ -148,7 +148,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// <param name="ignoreMissing">Ignore errors caused by the Mandatory attribute. Defaults to false.</param>
/// <param name="ignoreUnrecognized">Ignore CLI arguments that do not match the schema. Defaults to false.</param>
/// <param name="raiseOnUsage">Treat '--help' parameters as parse errors. Defaults to false.</param>
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
Expand All @@ -160,15 +160,15 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
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)

/// <summary>Parse AppSettings section of XML configuration only.</summary>
/// <param name="xmlConfigurationFile">If specified, parse AppSettings configuration from given xml configuration file.</param>
/// <param name="ignoreMissing">Ignore errors caused by the Mandatory attribute. Defaults to false.</param>
[<Obsolete("Use ArgumentParser.ParseConfiguration method instead")>]
member __.ParseAppSettings (?xmlConfigurationFile : string, ?ignoreMissing : bool) : ParseResult<'Template> =
member __.ParseAppSettings (?xmlConfigurationFile : string, ?ignoreMissing : bool) : ParseResults<'Template> =
let configurationReader =
match xmlConfigurationFile with
| None -> ConfigurationReader.FromAppSettings()
Expand All @@ -185,17 +185,17 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
__.ParseConfiguration(configurationReader, ?ignoreMissing = ignoreMissing)

/// <summary>
/// Converts a sequence of template argument inputs into a ParseResult instance
/// Converts a sequence of template argument inputs into a ParseResults instance
/// </summary>
/// <param name="inputs">Argument input sequence.</param>
member __.ToParseResult (inputs : seq<'Template>) : ParseResult<'Template> =
member __.ToParseResults (inputs : seq<'Template>) : ParseResults<'Template> =
mkParseResultFromValues argInfo errorHandler _usageStringCharacterWidth _programName helpTextMessage inputs

/// <summary>
/// Gets a subparser associated with specific subcommand instance
/// </summary>
/// <param name="expr">Expression providing the subcommand union constructor.</param>
member __.GetSubCommandParser (expr : Expr<ParseResult<'SubTemplate> -> 'Template>) : ArgumentParser<'SubTemplate> =
member __.GetSubCommandParser (expr : Expr<ParseResults<'SubTemplate> -> 'Template>) : ArgumentParser<'SubTemplate> =
let uci = expr2Uci expr
let case = argInfo.Cases.[uci.Tag]
match case.ParameterInfo with
Expand Down Expand Up @@ -276,15 +276,15 @@ type ArgumentParser with
[<AutoOpen>]
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 =
Expand Down
2 changes: 1 addition & 1 deletion src/Argu/ParseResult.fs → src/Argu/ParseResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open FSharp.Quotations

/// Argument parsing result holder.
[<Sealed; AutoSerializable(false); StructuredFormatDisplay("{StructuredFormatDisplay}")>]
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
Expand Down
2 changes: 1 addition & 1 deletion src/Argu/Parsers/Cli.fs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ let rec private parseCommandLinePartial (state : CliParseState) (argInfo : Union
let result =
existential.Accept { new ITemplateFunc<obj> 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
Expand Down
4 changes: 2 additions & 2 deletions src/Argu/Parsers/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) =
Expand All @@ -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)

/// <summary>
/// Combines two parse results, AppSettings and CLI, overriding where appropriate.
Expand Down
8 changes: 4 additions & 4 deletions src/Argu/PreCompute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IParseResult>.IsAssignableFrom t then NestedParseResult(t.GetGenericArguments().[0])
if typeof<IParseResult>.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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions tests/Argu.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module ``Argu Tests`` =
[<RequireSubcommand>]
type RequiredSubcommand =
| Foo
| [<CliPrefix(CliPrefix.None)>] Sub of ParseResult<CleanArgs>
| [<CliPrefix(CliPrefix.None)>] Sub of ParseResults<CleanArgs>
with
interface IArgParserTemplate with
member this.Usage = "required"
Expand Down Expand Up @@ -80,10 +80,10 @@ module ``Argu Tests`` =
| [<CliPrefix(CliPrefix.Dash)>] A
| [<CliPrefix(CliPrefix.Dash)>] B
| [<CliPrefix(CliPrefix.Dash)>] C
| [<CliPrefix(CliPrefix.None)>] Push of ParseResult<PushArgs>
| [<CliPrefix(CliPrefix.None)>] Clean of ParseResult<CleanArgs>
| [<CliPrefix(CliPrefix.None)>] Required of ParseResult<RequiredSubcommand>
| [<CliPrefix(CliPrefix.None)>] Unrecognized of ParseResult<GatherUnrecognizedSubcommand>
| [<CliPrefix(CliPrefix.None)>] Push of ParseResults<PushArgs>
| [<CliPrefix(CliPrefix.None)>] Clean of ParseResults<CleanArgs>
| [<CliPrefix(CliPrefix.None)>] Required of ParseResults<RequiredSubcommand>
| [<CliPrefix(CliPrefix.None)>] Unrecognized of ParseResults<GatherUnrecognizedSubcommand>
with
interface IArgParserTemplate with
member a.Usage =
Expand Down Expand Up @@ -449,25 +449,25 @@ module ``Argu Tests`` =

type ConflictingInheritedCliName =
| [<AltCommandLine("-f"); Inherit>] Force
| Nested of ParseResult<CleanArgs>
| Nested of ParseResults<CleanArgs>
with
interface IArgParserTemplate with
member __.Usage = "not tested"

type RecursiveArgument1 =
| Rec1 of ParseResult<RecursiveArgument2>
| Rec1 of ParseResults<RecursiveArgument2>
with
interface IArgParserTemplate with
member a.Usage = "foo"

and RecursiveArgument2 =
| Rec2 of ParseResult<RecursiveArgument3>
| Rec2 of ParseResults<RecursiveArgument3>
with
interface IArgParserTemplate with
member a.Usage = "bar"

and RecursiveArgument3 =
| Rec3 of ParseResult<RecursiveArgument1>
| Rec3 of ParseResults<RecursiveArgument1>
with
interface IArgParserTemplate with
member a.Usage = "baz"
Expand Down Expand Up @@ -614,7 +614,7 @@ module ``Argu Tests`` =

[<DisableHelpFlags>]
type NestedInherited =
| [<Inherit>] Nested of ParseResult<NoHelp>
| [<Inherit>] Nested of ParseResults<NoHelp>
with
interface IArgParserTemplate with
member a.Usage = "not tested here"
Expand All @@ -626,7 +626,7 @@ module ``Argu Tests`` =

[<Fact>]
let ``Fail on malformed case constructors`` () =
let result = parser.ToParseResult []
let result = parser.ToParseResults []
let wrapper = List
raises<ArgumentException> <@ result.Contains <@ fun (y : string) -> Log_Level 42 @> @>
raises<ArgumentException> <@ result.Contains <@ fun (y, x) -> Data(x,y) @> @>
Expand Down
4 changes: 2 additions & 2 deletions tests/Argu.Tests/tests.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ with
type GitArgs =
| [<Unique>] Listener of address:string * number:int
| Log_Level of level:int
| [<CliPrefix(CliPrefix.None)>]Push of options:ParseResult<PushArgs>
| [<CliPrefix(CliPrefix.None)>]Clean of suboptions:ParseResult<CleanArgs>
| [<CliPrefix(CliPrefix.None)>]Push of options:ParseResults<PushArgs>
| [<CliPrefix(CliPrefix.None)>]Clean of suboptions:ParseResults<CleanArgs>
| [<AltCommandLine("-E")>][<EqualsAssignment>]Environment_Variable of key:string * value:string
| Ports of tcp_port:int list
| Optional of num:int option
Expand Down

0 comments on commit 17e99a7

Please sign in to comment.