Skip to content

Commit

Permalink
Add command proc as example
Browse files Browse the repository at this point in the history
  • Loading branch information
abelbraaksma committed Apr 17, 2024
1 parent 5fb8a9a commit d37ab57
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/FSharp.Control.TaskSeq.Test/CEPoC.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,75 @@ open FSharp.Control
/// https://github.com/cannorin/FSharp.CommandLine/blob/master/src/FSharp.CommandLine/commands.fs
///
module Cmd =
open FSharp.CommandLine

let fileOption = commandOption {
names [ "f"; "file" ]
description "Name of a file to use (Default index: 0)"
takes (format("%s:%i").withNames [ "filename"; "index" ])
takes (format("%s").map (fun filename -> (filename, 0)))
suggests (fun _ -> [ CommandSuggestion.Files None ])
}

type Verbosity =
| Quiet
| Normal
| Full
| Custom of int

let verbosityOption = commandOption {
names [ "v"; "verbosity" ]
description "Display this amount of information in the log."
takes (regex @"q(uiet)?$" |> asConst Quiet)
takes (regex @"n(ormal)?$" |> asConst Quiet)
takes (regex @"f(ull)?$" |> asConst Full)
takes (format("custom:%i").map (fun level -> Custom level))
takes (format("c:%i").map (fun level -> Custom level))
}

let mainCommand () =
let x = CommandBuilder()

let c1 = command {
name "main"
description "The main command."
opt files in fileOption |> CommandOption.zeroOrMore

opt verbosity in verbosityOption
|> CommandOption.zeroOrExactlyOne
|> CommandOption.whenMissingUse Normal

do printfn "%A, %A" files verbosity
let! x = command { name "main" }
name "foo"
//for x in 1 .. 3 do
// yield 42

//for x in 1 .. 3 do
// yield 42

do printfn "%A, %A" files verbosity
let! x = command { name "main" }
description "The main command."

return "foo"
}

command {
let! x = c1
name "main"
description "The main command."
opt files in fileOption |> CommandOption.zeroOrMore

opt verbosity in verbosityOption
|> CommandOption.zeroOrExactlyOne
|> CommandOption.whenMissingUse Normal

do printfn "%A, %A" files verbosity
return "foo"
}

module CEs =

type M<'T, 'Vars> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<PackageReference Include="FSharp.CommandLine" Version="3.3.3805.29705" />
<PackageReference Include="FsUnit.xUnit" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit d37ab57

Please sign in to comment.