@@ -10,7 +10,7 @@ open FSharp.Reflection
1010/// The Argu type generates an argument parser given a type argument
1111/// that is an F# discriminated union. It can then be used to parse command line arguments
1212/// or XML configuration.
13- [<NoEquality; NoComparison; Sealed ; AutoSerializable( false ) >]
13+ [<NoEquality; NoComparison; AutoSerializable( false ) >]
1414type ArgumentParser < 'Template when 'Template :> IArgParserTemplate > private ( argInfo : UnionArgInfo , ? programName : string , ? description : string , ? errorHandler : IExiter ) =
1515 // memoize parser generation for given template type
1616 static let argInfoLazy = lazy ( preComputeUnionArgInfo< 'Template> ())
@@ -39,11 +39,16 @@ type ArgumentParser<'Template when 'Template :> IArgParserTemplate> private (arg
3939 new ArgumentParser< 'Template>( argInfoLazy.Value, ?programName = programName,
4040 ?description = description, ?errorHandler = errorHandler)
4141
42-
43- /// Returns true if top-level parser
44- /// and false if parser defined for a subcommand
45- member __.IsTopLevelParser = argInfo.TryGetParent() |> Option.isNone
46-
42+ /// Gets the help flags specified for the CLI parser
43+ member __.HelpFlags = argInfo.HelpParam.Flags
44+ /// Gets the help description specified for the CLI parser
45+ member __.HelpDescription = argInfo.HelpParam.Description
46+ /// Gets metadata for all union cases used by parser
47+ member __.GetArgumentCases () = argInfo.Cases |> Array.map ( fun p -> p.ToArgumentCaseInfo())
48+ /// Returns true if parser corresponds to a subcommand
49+ member __.IsSubCommandParser = argInfo.TryGetParent() |> Option.isSome
50+ /// If subcommand parsers, gets parent argument metadata
51+ member __.ParentInfo = argInfo.TryGetParent() |> Option.map ( fun p -> p.ToArgumentCaseInfo())
4752 /// Gets the default error handler used by the instance
4853 member __.ErrorHandler = errorHandler
4954
@@ -150,16 +155,24 @@ type ArgumentParser<'Template when 'Template :> IArgParserTemplate> private (arg
150155 /// Gets the F# union tag representation for given argument
151156 /// </summary >
152157 /// <param name =" value " >Argument instance.</param >
153- member __.GetTag ( value : 'Template ) : UnionCaseInfo =
158+ member __.GetTag ( value : 'Template ) : int =
159+ argInfo.TagReader.Value ( value :> obj)
160+
161+ /// <summary >
162+ /// Gets argument metadata for given argument instance.
163+ /// </summary >
164+ /// <param name =" value " >Argument instance.</param >
165+ member __.GetArgumentCaseInfo ( value : 'Template ) : ArgumentCaseInfo =
154166 let tag = argInfo.TagReader.Value ( value :> obj)
155- argInfo.Cases.[ tag]. UnionCaseInfo
167+ argInfo.Cases.[ tag]. ToArgumentCaseInfo ()
156168
157169 /// <summary >
158- /// Gets the F# union tag representation for given union case constructor
170+ /// Gets argument metadata for given union case constructor
159171 /// </summary >
160172 /// <param name =" ctorExpr " >Quoted union case constructor.</param >
161- member __.GetTag ( ctorExpr : Expr < 'Fields -> 'Template >) : UnionCaseInfo =
162- expr2Uci ctorExpr
173+ member __.GetArgumentCaseInfo ( ctorExpr : Expr < 'Fields -> 'Template >) : ArgumentCaseInfo =
174+ let uci = expr2Uci ctorExpr
175+ argInfo.Cases.[ uci.Tag]. ToArgumentCaseInfo()
163176
164177 /// <summary >
165178 /// Prints command line syntax. Useful for generating documentation.
@@ -212,5 +225,5 @@ module ArgumentParserUtils =
212225 ArgumentParser.Create< 'Template>() .ToParseResult( inputs)
213226
214227 /// gets the F# union tag representation of given argument instance
215- let tagOf ( input : 'Template ) : UnionCaseInfo =
228+ let tagOf ( input : 'Template ) : int =
216229 ArgumentParser.Create< 'Template>() .GetTag input
0 commit comments