Skip to content

Commit

Permalink
PipeBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
UnstoppableMango committed Jan 13, 2024
1 parent e324192 commit 808be58
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
1 change: 1 addition & 0 deletions CliWrap.FSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{BC5059
.editorconfig = .editorconfig
.gitignore = .gitignore
.githooks\pre-commit = .githooks\pre-commit
CliWrap.FSharp.sln.DotSettings = CliWrap.FSharp.sln.DotSettings
EndProjectSection
EndProject
Global
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ It attempts to mimic the builder pattern and `.With*` style methods.

```fsharp
let main args =
let built = command "dotnet" {
let cmd = command "dotnet" {
args = [ "build" ]
workingDirectory = "~/src/CliWrap.FSharp"
}
built.ExecuteAsync()
cmd.ExecuteAsync()
```

```fsharp
Expand All @@ -23,11 +23,21 @@ let main args = async {
args = [ "build" ]
workingDirectory = "~/src/CliWrap.FSharp"
}
result.ExitCode
}
```

```fsharp
let main args =
let cmd = pipeline {
"an inline string source"
Cli.wrap "echo"
}
cmd.ExecuteAsync()
```

## Idiomatic? This looks nothing like normal F# code!

I've only recently been diving further into the F# ecosystem, if something looks off please open an issue!
Expand Down
107 changes: 106 additions & 1 deletion src/CliWrap.FSharp/PipeBuilder.fs
Original file line number Diff line number Diff line change
@@ -1,9 +1,114 @@
[<AutoOpen>]
module UnMango.CliWrap.FSharp.PipeBuilder

open System
open System.ComponentModel
open System.IO
open System.Text
open System.Threading
open System.Threading.Tasks
open CliWrap

module private Tuple =
let map f (a, b) = (f a, f b)

Check warning on line 13 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L13

Added line #L13 was not covered by tests

type PipeBuilder() =

Check warning on line 15 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L15

Added line #L15 was not covered by tests
[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Run() = ()
member _.Run(state: Command) = state

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

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L17

Added line #L17 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Combine(source: Command, target: PipeTarget) = source.WithStandardErrorPipe(target)

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

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L20

Added line #L20 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, stream: Stream) =
this.Combine(source, PipeTarget.ToStream(stream))

Check warning on line 24 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L24

Added line #L24 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, builder: StringBuilder) =
this.Combine(source, PipeTarget.ToStringBuilder(builder))

Check warning on line 28 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L28

Added line #L28 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, f: string -> CancellationToken -> Task) =
this.Combine(source, PipeTarget.ToDelegate(f))

Check warning on line 32 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L32

Added line #L32 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, f: string -> Task) =
this.Combine(source, PipeTarget.ToDelegate(f))

Check warning on line 36 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L36

Added line #L36 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, f: string -> unit) =
this.Combine(source, PipeTarget.ToDelegate(f))

Check warning on line 40 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L40

Added line #L40 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, (stdout: PipeTarget, stderr: PipeTarget)) =
source.WithStandardOutputPipe(stdout).WithStandardErrorPipe(stderr)

Check warning on line 44 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L44

Added line #L44 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, target: Stream * Stream) =
this.Combine(source, target |> Tuple.map PipeTarget.ToStream)

Check warning on line 48 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L48

Added line #L48 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, target: StringBuilder * StringBuilder) =
this.Combine(source, target |> Tuple.map PipeTarget.ToStringBuilder)

Check warning on line 52 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L52

Added line #L52 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine
(
source: Command,
(stdout: string -> CancellationToken -> Task, stderr: string -> CancellationToken -> Task)
) =
this.Combine(source, (PipeTarget.ToDelegate(stdout), PipeTarget.ToDelegate(stderr)))

Check warning on line 60 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L60

Added line #L60 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, (stdout: string -> Task, stderr: string -> Task)) =
this.Combine(source, (PipeTarget.ToDelegate(stdout), PipeTarget.ToDelegate(stderr)))

Check warning on line 64 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L64

Added line #L64 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, (stdout: string -> unit, stderr: string -> unit)) =
this.Combine(source, (PipeTarget.ToDelegate(stdout), PipeTarget.ToDelegate(stderr)))

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

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L68

Added line #L68 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Combine(_: unit, source: PipeSource) = source

Check warning on line 71 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L71

Added line #L71 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Combine(source: PipeSource, command: Command) = command.WithStandardInputPipe(source)

Check warning on line 74 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L74

Added line #L74 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Stream, command: Command) =
this.Combine(PipeSource.FromStream(source), command)

Check warning on line 78 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L78

Added line #L78 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: ReadOnlyMemory<byte>, command: Command) =
this.Combine(PipeSource.FromBytes(source), command)

Check warning on line 82 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L82

Added line #L82 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: byte array, command: Command) =
this.Combine(PipeSource.FromBytes(source), command)

Check warning on line 86 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L86

Added line #L86 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source, command: Command) =
this.Combine(PipeSource.FromString(source), command)

Check warning on line 90 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L90

Added line #L90 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member this.Combine(source: Command, command: Command) =
this.Combine(PipeSource.FromCommand(source), command)

Check warning on line 94 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L94

Added line #L94 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Yield(x: PipeSource) = x

Check warning on line 97 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L97

Added line #L97 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Yield(x: Command) = x

Check warning on line 100 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L100

Added line #L100 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Yield(x: string) = x

Check warning on line 103 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L103

Added line #L103 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Yield(x: Stream) = x

Check warning on line 106 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L106

Added line #L106 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Yield(x: StringBuilder) = x

Check warning on line 109 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L109

Added line #L109 was not covered by tests

[<EditorBrowsable(EditorBrowsableState.Never)>]
member _.Delay f = f ()

Check warning on line 112 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L112

Added line #L112 was not covered by tests

let pipeline = PipeBuilder()

Check warning on line 114 in src/CliWrap.FSharp/PipeBuilder.fs

View check run for this annotation

Codecov / codecov/patch

src/CliWrap.FSharp/PipeBuilder.fs#L114

Added line #L114 was not covered by tests

0 comments on commit 808be58

Please sign in to comment.