Idiomatic F# support for CliWrap.
- NuGet:
dotnet add package UnMango.CliWrap.FSharp - GitHub Packages:
dotnet add package UnMango.CliWrap.FSharp -s github
Bindings for normal CliWrap commands are available in the Cli module.
let main args = async {
let! result =
Cli.wrap "dotnet"
|> Cli.args [ "build" ]
|> Cli.workDir "~/src/CliWrap.FSharp"
|> Cli.exec
return result.ExitCode
}Cancellation token overloads are available in Cli.Tasks.
let main args = task {
use cts = new CancellationTokenSource()
let! result =
Cli.wrap "dotnet"
|> Cli.args [ "build" ]
|> Cli.workDir "~/src/CliWrap.FSharp"
|> Cli.Task.exec cts.Token
return result.ExitCode
}let main args = task {
use graceful = new CancellationTokenSource()
use forceful = new CancellationTokenSource()
let! result =
Cli.wrap "dotnet"
|> Cli.args [ "build" ]
|> Cli.workDir "~/src/CliWrap.FSharp"
|> Cli.Task.execf forceful.Token graceful.Token
return result.ExitCode
}The core of the package is a simple computation expression that wraps CliWrap.Command.
It attempts to mimic the builder pattern and .With* style methods.
let main args =
let cmd = command "dotnet" {
args [ "build" ]
workingDirectory "~/src/CliWrap.FSharp"
}
cmd.ExecuteAsync()The computation expression also supports executing the command with exec.
let main args = task {
let! result = command "dotnet" {
args [ "build" ]
workingDirectory "~/src/CliWrap.FSharp"
exec
}
return result.ExitCode
}Cancellation is also supported.
let main args = task {
use cts = new CancellationTokenSource()
let! result = command "dotnet" {
args [ "build" ]
workingDirectory "~/src/CliWrap.FSharp"
exec cts.Token
}
return result.ExitCode
}CliWrap's buffered execution is supported with buffered.
let main args = task {
use cts = new CancellationTokenSource()
let! result = command "dotnet" {
args [ "build" ]
workingDirectory "~/src/CliWrap.FSharp"
buffered Encoding.UTF8 cts.Token
}
return result.ExitCode
}Asynchrony with F#'s Async<'T> is supported with async.
let main args = async {
use cts = new CancellationTokenSource()
let! result = command "dotnet" {
args [ "build" ]
workingDirectory "~/src/CliWrap.FSharp"
async cts.Token
}
return result.ExitCode
}CliWrap's piping functionality is supported via the pipeline computation expression.
let main args =
let cmd = pipeline {
"an inline string source"
Cli.wrap "echo"
}
cmd.ExecuteAsync()Limited support for piping is available with |>>.
let main args =
let cmd = Cli.wrap "yes" |>> Cli.wrap "echo"
cmd.ExecuteAsync()Trimming is supported, but FSharp.Core still has some work to do before full AOT is supported.
The idea to abuse F# computation expressions was inspired by Akkling.Hocon and FsHttp.
Obviously CliWrap was a big inspiration for this package.
If something looks off please open an issue! I've only recently been diving further into the F# ecosystem.
If renovate ever supports it!