@@ -11,13 +11,15 @@ open FSharp.Reflection
1111/// that is an F# discriminated union. It can then be used to parse command line arguments
1212/// or XML configuration.
1313[<AbstractClass; NoEquality; NoComparison; AutoSerializable( false ) >]
14- type ArgumentParser internal ( argInfo : UnionArgInfo , _programName : string , description : string option ,
14+ type ArgumentParser internal ( argInfo : UnionArgInfo , _programName : string , helpTextMessage : string option ,
1515 _ usageStringCharacterWidth : int, errorHandler : IExiter) =
1616
1717 /// Gets the help flags specified for the CLI parser
1818 member __.HelpFlags = argInfo.HelpParam.Flags
1919 /// Gets the help description specified for the CLI parser
2020 member __.HelpDescription = argInfo.HelpParam.Description
21+ /// Gets the message that will be displayed at the top of the help text
22+ member __.HelpTextMessage = helpTextMessage
2123 /// Returns true if parser corresponds to a subcommand
2224 member __.IsSubCommandParser = argInfo.TryGetParent() |> Option.isSome
2325 /// If subcommand parser, gets parent argument metadata
@@ -39,7 +41,7 @@ type ArgumentParser internal (argInfo : UnionArgInfo, _programName : string, des
3941 e.Accept {
4042 new ITemplateFunc< ArgumentParser> with
4143 member __. Invoke< 'Template when 'Template :> IArgParserTemplate> () =
42- new ArgumentParser< 'Template>( nu, _ programName, description , _ usageStringCharacterWidth, errorHandler) :> _
44+ new ArgumentParser< 'Template>( nu, _ programName, helpTextMessage , _ usageStringCharacterWidth, errorHandler) :> _
4345 })
4446 |> Seq.toList
4547
@@ -50,7 +52,7 @@ type ArgumentParser internal (argInfo : UnionArgInfo, _programName : string, des
5052 member __.PrintUsage (? message : string , ? programName : string , ? usageStringCharacterWidth : int ) : string =
5153 let programName = defaultArg programName _ programName
5254 let usageStringCharacterWidth = defaultArg usageStringCharacterWidth _ usageStringCharacterWidth
53- printUsage argInfo programName usageStringCharacterWidth message |> StringExpr.build
55+ mkUsageString argInfo programName usageStringCharacterWidth message |> StringExpr.build
5456
5557 /// <summary >
5658 /// Prints command line syntax. Useful for generating documentation.
@@ -60,7 +62,7 @@ type ArgumentParser internal (argInfo : UnionArgInfo, _programName : string, des
6062 member __.PrintCommandLineSyntax (? programName : string , ? usageStringCharacterWidth : int ) : string =
6163 let programName = defaultArg programName _ programName
6264 let usageStringCharacterWidth = defaultArg usageStringCharacterWidth _ usageStringCharacterWidth
63- printCommandLineSyntax argInfo " " usageStringCharacterWidth programName |> StringExpr.build
65+ mkCommandLineSyntax argInfo " " usageStringCharacterWidth programName |> StringExpr.build
6466
6567 /// <summary >
6668 /// Enables access to the typed API of an ArgumentParser
@@ -74,36 +76,36 @@ type ArgumentParser internal (argInfo : UnionArgInfo, _programName : string, des
7476/// or XML configuration.
7577and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
7678 ArgumentParser<'Template when 'Template :> IArgParserTemplate>
77- internal ( argInfo : UnionArgInfo , _programName : string , description : string option ,
79+ internal ( argInfo : UnionArgInfo , _programName : string , helpTextMessage : string option ,
7880 _usageStringCharacterWidth : int , errorHandler : IExiter ) =
7981
80- inherit ArgumentParser( argInfo, _ programName, description , _ usageStringCharacterWidth, errorHandler)
82+ inherit ArgumentParser( argInfo, _ programName, helpTextMessage , _ usageStringCharacterWidth, errorHandler)
8183
8284 // memoize parser generation for given template type
8385 static let argInfoLazy = lazy ( preComputeUnionArgInfo< 'Template> ())
8486
85- let mkUsageString argInfo msgOpt = printUsage argInfo _ programName _ usageStringCharacterWidth msgOpt |> StringExpr.build
87+ let mkUsageString argInfo msgOpt = mkUsageString argInfo _ programName _ usageStringCharacterWidth msgOpt |> StringExpr.build
8688
8789 let (| ParserExn | _ |) ( e : exn ) =
8890 match e with
8991 // do not display usage for App.Config parameter errors
9092 | ParseError ( msg, ErrorCode.AppSettings, _) -> Some( ErrorCode.AppSettings, msg)
9193 | ParseError ( msg, id, aI) -> Some ( id, mkUsageString aI ( Some msg))
92- | HelpText aI -> Some ( ErrorCode.HelpText, mkUsageString aI description )
94+ | HelpText aI -> Some ( ErrorCode.HelpText, mkUsageString aI helpTextMessage )
9395 | _ -> None
9496
9597 /// <summary >
9698 /// Creates a new parser instance based on supplied F# union template.
9799 /// </summary >
98100 /// <param name =" programName " >Program identifier, e.g. 'cat'. Defaults to the current executable name.</param >
99- /// <param name =" description " >Program description placed at the top of the usage string .</param >
101+ /// <param name =" helpTextMessage " >Message that will be displayed at the top of the help text .</param >
100102 /// <param name =" usageStringCharacterWidth " >Text width used when formatting the usage string. Defaults to 80 chars.</param >
101103 /// <param name =" errorHandler " >The implementation of IExiter used for error handling. Exception is default.</param >
102- new (? programName : string , ? description : string , ? usageStringCharacterWidth : int , ? errorHandler : IExiter ) =
104+ new (? programName : string , ? helpTextMessage : string , ? usageStringCharacterWidth : int , ? errorHandler : IExiter ) =
103105 let usageStringCharacterWidth = defaultArg usageStringCharacterWidth 80
104106 let programName = match programName with Some pn -> pn | None -> currentProgramName.Value
105107 let errorHandler = match errorHandler with Some e -> e | None -> new ExceptionExiter() :> _
106- new ArgumentParser< 'Template>( argInfoLazy.Value, programName, description , usageStringCharacterWidth, errorHandler)
108+ new ArgumentParser< 'Template>( argInfoLazy.Value, programName, helpTextMessage , usageStringCharacterWidth, errorHandler)
107109
108110 /// <summary >Parse command line arguments only.</summary >
109111 /// <param name =" inputs " >The command line input. Taken from System.Environment if not specified.</param >
@@ -117,11 +119,11 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
117119 let inputs = match inputs with None -> getEnvironmentCommandLineArgs () | Some args -> args
118120
119121 try
120- let cliResults = parseCommandLine argInfo _ programName description _ usageStringCharacterWidth errorHandler raiseOnUsage ignoreUnrecognized inputs
122+ let cliResults = parseCommandLine argInfo _ programName helpTextMessage _ usageStringCharacterWidth errorHandler raiseOnUsage ignoreUnrecognized inputs
121123 let ignoreMissing = ( cliResults.IsUsageRequested && not raiseOnUsage) || ignoreMissing
122124 let results = postProcessResults argInfo ignoreMissing None ( Some cliResults)
123125
124- new ParseResult< 'Template>( argInfo, results, _ programName, description , _ usageStringCharacterWidth, errorHandler)
126+ new ParseResult< 'Template>( argInfo, results, _ programName, helpTextMessage , _ usageStringCharacterWidth, errorHandler)
125127
126128 with ParserExn ( errorCode, msg) -> errorHandler.Exit ( msg, errorCode)
127129
@@ -135,7 +137,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
135137 let appSettingsResults = parseKeyValueConfig configurationReader argInfo
136138 let results = postProcessResults argInfo ignoreMissing ( Some appSettingsResults) None
137139
138- new ParseResult< 'Template>( argInfo, results, _ programName, description , _ usageStringCharacterWidth, errorHandler)
140+ new ParseResult< 'Template>( argInfo, results, _ programName, helpTextMessage , _ usageStringCharacterWidth, errorHandler)
139141
140142 with ParserExn ( errorCode, msg) -> errorHandler.Exit ( msg, errorCode)
141143
@@ -155,10 +157,10 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
155157
156158 try
157159 let appSettingsResults = parseKeyValueConfig configurationReader argInfo
158- let cliResults = parseCommandLine argInfo _ programName description _ usageStringCharacterWidth errorHandler raiseOnUsage ignoreUnrecognized inputs
160+ let cliResults = parseCommandLine argInfo _ programName helpTextMessage _ usageStringCharacterWidth errorHandler raiseOnUsage ignoreUnrecognized inputs
159161 let results = postProcessResults argInfo ignoreMissing ( Some appSettingsResults) ( Some cliResults)
160162
161- new ParseResult< 'Template>( argInfo, results, _ programName, description , _ usageStringCharacterWidth, errorHandler)
163+ new ParseResult< 'Template>( argInfo, results, _ programName, helpTextMessage , _ usageStringCharacterWidth, errorHandler)
162164
163165 with ParserExn ( errorCode, msg) -> errorHandler.Exit ( msg, errorCode)
164166
@@ -187,7 +189,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
187189 /// </summary >
188190 /// <param name =" inputs " >Argument input sequence.</param >
189191 member __.ToParseResult ( inputs : seq < 'Template >) : ParseResult < 'Template > =
190- mkParseResultFromValues argInfo errorHandler _ usageStringCharacterWidth _ programName description inputs
192+ mkParseResultFromValues argInfo errorHandler _ usageStringCharacterWidth _ programName helpTextMessage inputs
191193
192194 /// <summary >
193195 /// Gets a subparser associated with specific subcommand instance
@@ -198,7 +200,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
198200 let case = argInfo.Cases.[ uci.Tag]
199201 match case.ParameterInfo with
200202 | NestedUnion (_, nestedUnion) ->
201- new ArgumentParser< 'SubTemplate>( nestedUnion, _ programName, description , _ usageStringCharacterWidth, errorHandler)
203+ new ArgumentParser< 'SubTemplate>( nestedUnion, _ programName, helpTextMessage , _ usageStringCharacterWidth, errorHandler)
202204 | _ -> arguExn " internal error when fetching subparser %O ." uci
203205
204206 /// <summary >
@@ -226,7 +228,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
226228
227229 /// <summary >Prints parameters in command line format. Useful for argument string generation.</summary >
228230 member __.PrintCommandLineArguments ( args : 'Template list ) : string [] =
229- printCommandLineArgs argInfo ( Seq.cast args) |> Seq.toArray
231+ mkCommandLineArgs argInfo ( Seq.cast args) |> Seq.toArray
230232
231233 /// <summary >Prints parameters in command line format. Useful for argument string generation.</summary >
232234 member __.PrintCommandLineArgumentsFlat ( args : 'Template list ) : string =
@@ -237,7 +239,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
237239 /// <param name =" printComments " >Print XML comments over every configuration entry.</param >
238240 member __.PrintAppSettingsArguments ( args : 'Template list , ? printComments : bool ) : string =
239241 let printComments = defaultArg printComments true
240- let xmlDoc = printAppSettings argInfo printComments args
242+ let xmlDoc = mkAppSettingsDocument argInfo printComments args
241243 use writer = { new System.IO.StringWriter() with member __.Encoding = System.Text.Encoding.UTF8 }
242244 xmlDoc.Save writer
243245 writer.Flush()
@@ -264,11 +266,11 @@ type ArgumentParser with
264266 /// which must be an F# Discriminated Union.
265267 /// </summary >
266268 /// <param name =" programName " >Program identifier, e.g. 'cat'. Defaults to the current executable name.</param >
267- /// <param name =" description " >Program description placed at the top of the usage string .</param >
269+ /// <param name =" helpTextMessage " >Message that will be displayed at the top of the help text .</param >
268270 /// <param name =" usageStringCharacterWidth " >Text width used when formatting the usage string. Defaults to 80 chars.</param >
269271 /// <param name =" errorHandler " >The implementation of IExiter used for error handling. Exception is default.</param >
270- static member Create < 'Template when 'Template :> IArgParserTemplate >(? programName : string , ? description : string , ? usageStringCharacterWidth : int , ? errorHandler : IExiter ) =
271- new ArgumentParser< 'Template>( ?programName = programName, ?description = description , ?errorHandler = errorHandler, ?usageStringCharacterWidth = usageStringCharacterWidth)
272+ static member Create < 'Template when 'Template :> IArgParserTemplate >(? programName : string , ? helpTextMessage : string , ? usageStringCharacterWidth : int , ? errorHandler : IExiter ) =
273+ new ArgumentParser< 'Template>( ?programName = programName, ?helpTextMessage = helpTextMessage , ?errorHandler = errorHandler, ?usageStringCharacterWidth = usageStringCharacterWidth)
272274
273275
274276[<AutoOpen>]
0 commit comments