@@ -10,6 +10,75 @@ open FSharp.Control
1010/// https://github.com/cannorin/FSharp.CommandLine/blob/master/src/FSharp.CommandLine/commands.fs
1111///
1212
13+ module Cmd =
14+ open FSharp.CommandLine
15+
16+ let fileOption = commandOption {
17+ names [ " f" ; " file" ]
18+ description " Name of a file to use (Default index: 0)"
19+ takes ( format( " %s :%i " ). withNames [ " filename" ; " index" ])
20+ takes ( format( " %s " ). map ( fun filename -> ( filename, 0 )))
21+ suggests ( fun _ -> [ CommandSuggestion.Files None ])
22+ }
23+
24+ type Verbosity =
25+ | Quiet
26+ | Normal
27+ | Full
28+ | Custom of int
29+
30+ let verbosityOption = commandOption {
31+ names [ " v" ; " verbosity" ]
32+ description " Display this amount of information in the log."
33+ takes ( regex @" q(uiet)?$" |> asConst Quiet)
34+ takes ( regex @" n(ormal)?$" |> asConst Quiet)
35+ takes ( regex @" f(ull)?$" |> asConst Full)
36+ takes ( format( " custom:%i " ). map ( fun level -> Custom level))
37+ takes ( format( " c:%i " ). map ( fun level -> Custom level))
38+ }
39+
40+ let mainCommand () =
41+ let x = CommandBuilder()
42+
43+ let c1 = command {
44+ name " main"
45+ description " The main command."
46+ opt files in fileOption |> CommandOption.zeroOrMore
47+
48+ opt verbosity in verbosityOption
49+ |> CommandOption.zeroOrExactlyOne
50+ |> CommandOption.whenMissingUse Normal
51+
52+ do printfn " %A , %A " files verbosity
53+ let! x = command { name " main" }
54+ name " foo"
55+ //for x in 1 .. 3 do
56+ // yield 42
57+
58+ //for x in 1 .. 3 do
59+ // yield 42
60+
61+ do printfn " %A , %A " files verbosity
62+ let! x = command { name " main" }
63+ description " The main command."
64+
65+ return " foo"
66+ }
67+
68+ command {
69+ let! x = c1
70+ name " main"
71+ description " The main command."
72+ opt files in fileOption |> CommandOption.zeroOrMore
73+
74+ opt verbosity in verbosityOption
75+ |> CommandOption.zeroOrExactlyOne
76+ |> CommandOption.whenMissingUse Normal
77+
78+ do printfn " %A , %A " files verbosity
79+ return " foo"
80+ }
81+
1382module CEs =
1483
1584 type M < 'T , 'Vars > = {
0 commit comments