Skip to content

Commit

Permalink
Merge pull request #25 from theimowski/print_command_line_syntax
Browse files Browse the repository at this point in the history
Print command line syntax
  • Loading branch information
eiriktsarpalis committed Feb 5, 2015
2 parents ded8bed + ad625f7 commit 02dfd11
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/UnionArgParser/UnParsers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@

args |> Seq.collect printEntry |> Seq.toArray

/// <summary>
/// print the command line syntax
/// </summary>
/// <param name="argInfo"></param>
let printCommandLineSyntax (argInfo : ArgInfo list) =
let sorted =
argInfo
|> List.filter (fun ai -> not ai.Hidden)
|> List.sortBy (fun ai -> not ai.IsFirst, ai.IsRest)

stringB {
for aI in sorted do
if not aI.Mandatory then yield "["
match aI.CommandLineNames with
| [] -> ()
| h :: t ->
if aI.Mandatory && not <| List.isEmpty t then yield "("
yield h
for n in t do
yield "|"
yield n
if aI.Mandatory && not <| List.isEmpty t then yield ")"

match aI.IsEqualsAssignment with
| true ->
yield sprintf "=<%O>" aI.FieldParsers.[0]
| false ->
for p in aI.FieldParsers do
yield sprintf " <%O>" p

if aI.IsRest then yield " ..."

if not aI.Mandatory then yield "]"
if aI.Id <> (Seq.last sorted).Id then yield " "
} |> String.build

/// <summary>
/// returns an App.Config XElement given a set of config parameters
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions src/UnionArgParser/UnionArgParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@
/// <param name="message">The message to be displayed on top of the usage string.</param>
member __.Usage (?message : string) : string = printUsage message argInfo

/// <summary>Prints command line syntax. Useful for generating documentation.</summary>
member __.PrintCommandLineSyntax () : string =
printCommandLineSyntax argInfo

/// <summary>Prints parameters in command line format. Useful for argument string generation.</summary>
member __.PrintCommandLine (args : 'Template list) : string [] =
printCommandLineArgs argInfo args
Expand Down

0 comments on commit 02dfd11

Please sign in to comment.