Skip to content

Commit d37ab57

Browse files
committed
Add command proc as example
1 parent 5fb8a9a commit d37ab57

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/FSharp.Control.TaskSeq.Test/CEPoC.fs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1382
module CEs =
1483

1584
type M<'T, 'Vars> = {

src/FSharp.Control.TaskSeq.Test/FSharp.Control.TaskSeq.Test.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
<PackageReference Include="FSharp.CommandLine" Version="3.3.3805.29705" />
6767
<PackageReference Include="FsUnit.xUnit" Version="6.0.0" />
6868
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
69+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
70+
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
6971
<PackageReference Include="xunit" Version="2.7.0" />
7072
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
7173
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)