UnMango.CliWrap.FSharp
0.2.0
dotnet add package UnMango.CliWrap.FSharp --version 0.2.0
NuGet\Install-Package UnMango.CliWrap.FSharp -Version 0.2.0
<PackageReference Include="UnMango.CliWrap.FSharp" Version="0.2.0" />
<PackageVersion Include="UnMango.CliWrap.FSharp" Version="0.2.0" />
<PackageReference Include="UnMango.CliWrap.FSharp" />
paket add UnMango.CliWrap.FSharp --version 0.2.0
#r "nuget: UnMango.CliWrap.FSharp, 0.2.0"
#:package UnMango.CliWrap.FSharp@0.2.0
#addin nuget:?package=UnMango.CliWrap.FSharp&version=0.2.0
#tool nuget:?package=UnMango.CliWrap.FSharp&version=0.2.0
CliWrap.FSharp
Idiomatic F# support for CliWrap.
Install
- NuGet:
dotnet add package UnMango.CliWrap.FSharp - GitHub Packages:
dotnet add package UnMango.CliWrap.FSharp -s github
Usage
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
}
Buffered execution captures standard output and standard error, and the CommandResult active patterns match on the result.
let main args = async {
let! result =
Cli.wrap "git"
|> Cli.args [ "status"; "--short" ]
|> Cli.resourcePolicyf _.SetPriority(ProcessPriorityClass.BelowNormal)
|> Cli.validation CommandResultValidation.None
|> Cli.execBuffered
match result with
| CommandResult.Buffered(0, stdout, _) -> printfn "%s" stdout
| CommandResult.Buffered(code, _, stderr) -> eprintfn "git exited with %i: %s" code stderr
}
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
}
Event streams
CliWrap's event streams are supported in two styles.
Both produce the same command events, which you can match with the Started, StdOut, StdErr and Exited active pattern.
Observe pushes events to subscribers as an IObservable<CommandEvent>, so F#'s Observable module works with it.
// Disposing the subscription stops the process
let subscription =
Cli.wrap "dotnet"
|> Cli.args [ "build" ]
|> Cli.observe CancellationToken.None
|> Observable.subscribe (function
| Started pid -> printfn $"Started %d{pid}"
| StdOut line -> printfn $"%s{line}"
| StdErr line -> eprintfn $"%s{line}"
| Exited code -> printfn $"Exited with %d{code}")
Listen pulls events as an IAsyncEnumerable<CommandEvent>.
With FSharp.Control.TaskSeq opened, task can loop over it.
open FSharp.Control
let main args = task {
use cts = new CancellationTokenSource()
let events = command "dotnet" {
args [ "build" ]
listen cts.Token
}
for event in events do
match event with
| StdOut line -> printfn $"%s{line}"
| _ -> ()
}
Both styles have the same set of overloads.
Cli |
command { } |
|
|---|---|---|
observe / listen |
No cancellation | |
observe ct / listen ct |
observe ct / listen ct |
Cancellation |
observee encoding ct / listene encoding ct |
observe encoding ct / listen encoding ct |
One encoding for standard output and standard error |
observef forceful graceful / listenf forceful graceful |
Forceful and graceful cancellation | |
observe stdoutEnc stderrEnc forceful graceful / listen ... |
Everything |
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()
Each command's standard output is piped into the next command's standard input, in order.
A leading string, Stream, byte[], ReadOnlyMemory<byte> or PipeSource feeds the first command.
A single trailing PipeTarget, Stream, StringBuilder or line delegate takes the last command's standard output,
and a trailing pair of targets takes its standard output and standard error, in that order.
let main args =
let stdout = StringBuilder()
let stderr = StringBuilder()
let cmd = pipeline {
"Hello world"
Cli.wrap "cat"
Cli.wrap "head" |> Cli.args [ "-c"; "5" ]
stdout, stderr
}
cmd.ExecuteAsync()
Limited support for piping is available with |>>.
let main args =
let cmd = Cli.wrap "yes" |>> Cli.wrap "echo"
cmd.ExecuteAsync()
AOT Compatibility
Trimming is supported, but FSharp.Core still has some work to do before full AOT is supported.
https://github.com/dotnet/fsharp/issues/13398
Contributing
Contributions are welcome! See CONTRIBUTING.md for how to build, test, and submit changes. To report a security vulnerability, follow SECURITY.md instead of opening an issue.
Inspirations
The idea to abuse F# computation expressions was inspired by Akkling.Hocon and FsHttp.
Obviously CliWrap was a big inspiration for this package.
Q/A
Idiomatic? This looks nothing like the F# I write!
If something looks off please open an issue! I've only recently been diving further into the F# ecosystem.
Why not paket?
If renovate ever supports it!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CliWrap (>= 3.10.5)
- FSharp.Core (>= 6.0.0)
-
.NETStandard 2.1
- CliWrap (>= 3.10.5)
- FSharp.Core (>= 6.0.0)
-
net10.0
- CliWrap (>= 3.10.5)
- FSharp.Core (>= 6.0.0)
-
net9.0
- CliWrap (>= 3.10.5)
- FSharp.Core (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.0 | 44 | 11/22/2026 |
| 0.1.0 | 50 | 11/22/2026 |
| 0.0.13-alpha.0.94 | 41 | 11/22/2026 |
| 0.0.13-alpha.0.93 | 41 | 11/22/2026 |
| 0.0.13-alpha.0.92 | 40 | 11/22/2026 |
| 0.0.13-alpha.0.91 | 41 | 11/22/2026 |
| 0.0.13-alpha.0.90 | 48 | 11/21/2026 |
| 0.0.13-alpha.0.89 | 42 | 11/21/2026 |
| 0.0.13-alpha.0.88 | 43 | 11/21/2026 |
| 0.0.13-alpha.0.87 | 43 | 11/21/2026 |
| 0.0.13-alpha.0.86 | 46 | 11/21/2026 |
| 0.0.13-alpha.0.85 | 47 | 11/21/2026 |
| 0.0.13-alpha.0.83 | 44 | 11/20/2026 |
| 0.0.13-alpha.0.82 | 57 | 11/16/2026 |
| 0.0.13-alpha.0.81 | 55 | 11/15/2026 |
| 0.0.13-alpha.0.80 | 68 | 11/11/2026 |
| 0.0.13-alpha.0.79 | 57 | 11/11/2026 |
| 0.0.13-alpha.0.78 | 55 | 11/11/2026 |
| 0.0.13-alpha.0.77 | 48 | 11/11/2026 |
| 0.0.13-alpha.0.76 | 54 | 11/11/2026 |