Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ExecBuilder and move execution into CommandBuilder #7

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CliWrap.FSharp.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand All @@ -25,6 +25,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{FE346152-5716-4224-9B25-C6B3815C70CA}"
ProjectSection(SolutionItems) = preProject
.github\workflows\main.yml = .github\workflows\main.yml
.github\renovate.json = .github\renovate.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{BC50591F-A365-4A92-9FDC-4CD2D75EE6A4}"
Expand Down
60 changes: 55 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CliWrap.FSharp

Idiomatic F# support for CliWrap
Idiomatic F# support for CliWrap.

## Usage

Expand All @@ -17,11 +17,59 @@ let main args =
cmd.ExecuteAsync()
```

The computation expression also supports executing the command with `exec`.

```fsharp
let main args = task {
let! result = command "dotnet" {
args = [ "build" ]
workingDirectory = "~/src/CliWrap.FSharp"
exec
}

result.ExitCode
}
```

Cancellation is also supported.

```fsharp
let main args = task {
use cts = new CancellationTokenSource()
let! result = command "dotnet" {
args = [ "build" ]
workingDirectory = "~/src/CliWrap.FSharp"
exec cts.Token
}

result.ExitCode
}
```

CliWrap's buffered execution is supported with `buffered`.

```fsharp
let main args = task {
use cts = new CancellationTokenSource()
let! result = command "dotnet" {
args = [ "build" ]
workingDirectory = "~/src/CliWrap.FSharp"
buffered Encoding.UTF8 cts.Token
}

result.ExitCode
}
```

Asynchrony with F#'s `Async<'T>` is supported with `async`.

```fsharp
let main args = async {
let! result = exec "dotnet" {
use cts = new CancellationTokenSource()
let! result = command "dotnet" {
args = [ "build" ]
workingDirectory = "~/src/CliWrap.FSharp"
async cts.Token
}

result.ExitCode
Expand All @@ -38,10 +86,12 @@ let main args =
cmd.ExecuteAsync()
```

## Idiomatic? This looks nothing like normal F# code!
## Q/A

### Idiomatic? This looks nothing like the F# I write!

I've only recently been diving further into the F# ecosystem, if something looks off please open an issue!
If something looks off please open an issue! I've only recently been diving further into the F# ecosystem.

## Why not paket?
### Why not paket?

If renovate ever [supports it](https://github.com/renovatebot/renovate/issues/11211)!
1 change: 0 additions & 1 deletion src/CliWrap.FSharp/CliWrap.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<Compile Include="Pipes.fs" />
<Compile Include="PipeBuilder.fs" />
<Compile Include="CommandBuilder.fs" />
<Compile Include="ExecBuilder.fs" />
<None Include="packages.lock.json" />
</ItemGroup>

Expand Down
35 changes: 35 additions & 0 deletions src/CliWrap.FSharp/CommandBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
module UnMango.CliWrap.FSharp.CommandBuilder

open System.ComponentModel
open System.Text
open CliWrap
open CliWrap.Buffered

type CommandBuilder(target: string) =
[<EditorBrowsable(EditorBrowsableState.Never)>]
Expand All @@ -11,6 +13,12 @@
[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Run(command: Command) = command

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Run<'T>(command: CommandTask<'T>) = command

Check warning on line 17 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L17

Added line #L17 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Run<'T>(task: Async<'T>) = task

Check warning on line 20 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L20

Added line #L20 was not covered by tests

[<CustomOperation("env")>]
member _.Env(command: Command, env) = Cli.env env command

Expand Down Expand Up @@ -47,4 +55,31 @@
[<CustomOperation("validation")>]
member _.Validation(command: Command, validation) = Cli.validation validation command

[<CustomOperation("exec")>]
member _.Exec(command: Command) = command.ExecuteAsync()

Check warning on line 59 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L59

Added line #L59 was not covered by tests

[<CustomOperation("exec")>]
member _.Exec(command: Command, cancellationToken) = command.ExecuteAsync(cancellationToken)

Check warning on line 62 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L62

Added line #L62 was not covered by tests

[<CustomOperation("buffered")>]
member _.Buffered(command: Command) = command.ExecuteBufferedAsync()

Check warning on line 65 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L65

Added line #L65 was not covered by tests

[<CustomOperation("buffered")>]
member _.Buffered(command: Command, encoding: Encoding) = command.ExecuteBufferedAsync(encoding)

Check warning on line 68 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L68

Added line #L68 was not covered by tests

[<CustomOperation("buffered")>]
member _.Buffered(command: Command, encoding, cancellationToken) =
command.ExecuteBufferedAsync(encoding, cancellationToken)

Check warning on line 72 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L72

Added line #L72 was not covered by tests

[<CustomOperation("async")>]
member _.Async<'T>(task: CommandTask<'T>) =
task |> CommandTask.op_Implicit |> Async.AwaitTask

Check warning on line 76 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L76

Added line #L76 was not covered by tests

[<CustomOperation("async")>]
member this.Async(command: Command) = this.Async(command.ExecuteAsync())

Check warning on line 79 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L79

Added line #L79 was not covered by tests

[<CustomOperation("async")>]
member this.Async(command: Command, cancellationToken) =
this.Async(command.ExecuteAsync(cancellationToken))

Check warning on line 83 in src/CliWrap.FSharp/CommandBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/CommandBuilder.fs#L83

Added line #L83 was not covered by tests

let command target = CommandBuilder(target)
41 changes: 0 additions & 41 deletions src/CliWrap.FSharp/ExecBuilder.fs

This file was deleted.