Skip to content

Commit

Permalink
args is too common to use as common expression (#10)
Browse files Browse the repository at this point in the history
* args is too common to use as common expression

* rename more arguments

* fix pushes hopefully
  • Loading branch information
Mpdreamz authored Jan 7, 2024
1 parent 4a906e7 commit 9213de6
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
if: github.event_name == 'push' && startswith(github.ref, 'refs/heads')
shell: bash
run: |
until dotnet nuget push build/output/*.nupkg -k ${{secrets.GITHUB_TOKEN}} --skip-duplicate --no-symbols true; do echo "Retrying"; sleep 1; done;
until dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.GITHUB_TOKEN}} --skip-duplicate --no-symbols; do echo "Retrying"; sleep 1; done;
- run: ./build.sh generatereleasenotes -s true
name: Generate release notes for tag
Expand All @@ -58,6 +58,6 @@ jobs:
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags')
name: Create or update release for tag on github

- run: dotnet nuget push build/output/*.nupkg -k ${{secrets.NUGET_ORG_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols true
- run: dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.NUGET_ORG_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate --no-symbols
name: release to nuget.org
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags')
30 changes: 22 additions & 8 deletions examples/ScratchPad.Fs/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ let _ = shell {
exec "uname"
}

let a: string list = [""]
temp { run }
temp { run "x" }
temp { run "x" "x" }
temp { run "x" [] }
temp { run "x" a }

let dotnetVersion = exec {
binary "dotnet"
args "--help"
arguments "--help"
filter_output (fun l -> l.Line.Contains "clean")
filter (fun l -> l.Line.Contains "clean")
}

printfn "Found lines %i" dotnetVersion.Length


exec {
binary "dotnet"
args "--help"
arguments "--help"
env Map[("key", "value")]
workingDirectory "."
working_dir "."
send_control_c false
timeout (TimeSpan.FromSeconds(10))
thread_wrap false
Expand All @@ -27,22 +37,26 @@ exec {

let helpStatus = exec {
binary "dotnet"
args "--help"
arguments "--help"
exit_code
}

let helpOutput = exec {
binary "dotnet"
args "--help"
arguments "--help"
output
}

printfn "Found lines %i" dotnetVersion.Length
let dotnet = exec { binary "dotnet" }

exec {
binary "dotnet"
let x = exec {
options dotnet
run_args ["restore"; "--help"]
}

let args: string list = [""]
exec { run "dotnet" " "}
exec { run "dotnet" args }

let _ = shell { exec "dotnet" a }
let statusCode = exec { exit_code_of "dotnet" " "}
147 changes: 101 additions & 46 deletions src/Proc.Fs/Bindings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type ShellBuilder() =

member t.Yield _ = ExecOptions.Empty

[<CustomOperation("workingDirectory")>]
[<CustomOperation("working_dir")>]
member inline this.WorkingDirectory(opts, workingDirectory: string) =
{ opts with WorkingDirectory = Some workingDirectory }

Expand Down Expand Up @@ -90,54 +90,126 @@ type ShellBuilder() =
Proc.Exec(execArgs) |> ignore
opts


let shell = ShellBuilder()

type TempBuilder() =

member t.Yield _ = ExecOptions.Empty

[<CustomOperation("run")>]
member this.Run2(opts, binary, [<ParamArray>] args: string array) =
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

[<CustomOperation("run")>]
member this.Run2(opts, binary, args: string list) =
let opts = { opts with Binary = binary; Arguments = Some args}
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

[<CustomOperation("run")>]
member this.Run2(opts) =
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

let temp = TempBuilder()


type ExecBuilder() =

member t.Yield _ = ExecOptions.Empty

///<summary>Runs <paramref name="binary"/> using <paramref name="arguments"/> immediately</summary>
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
/// <param name="binary">The binary to execute</param>
/// <param name="arguments">the arguments to pass on to the binary being executed</param>
[<CustomOperation("run")>]
member this.Execute(opts, binary, [<ParamArray>] arguments: string array) =
let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)}
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

///<summary>Runs <paramref name="binary"/> using <paramref name="arguments"/> immediately</summary>
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
/// <param name="binary">The binary to execute</param>
/// <param name="arguments">the arguments to pass on to the binary being executed</param>
[<CustomOperation("run")>]
member this.Execute(opts, binary, arguments: string list) =
let opts = { opts with Binary = binary; Arguments = Some arguments}
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

///<summary>
/// Runs the <see cref="ExecOptions"/> the computation build thus far.
/// <para>Needs at least `binary` to be specified</para>
/// </summary>
[<CustomOperation("run")>]
member this.Execute(opts) =
if opts.Binary = "" then failwithf "No binary specified to exec computation expression"
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

///<summary>Supply external <see cref="ExecOptions"/> to bootstrap</summary>
[<CustomOperation("options")>]
member this.Options(_, reuseOptions: ExecOptions) =
reuseOptions

///<summary>The binary to execute</summary>
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
/// <param name="binary">The binary to execute</param>
[<CustomOperation("binary")>]
member this.Binary(opts, binary) =
{ opts with Binary = binary }

[<CustomOperation("args")>]
member inline this.Arguments(opts, [<ParamArray>] args: string array) =
{ opts with Arguments = Some (args |> List.ofArray) }

[<CustomOperation("args")>]
member inline this.Arguments(opts, args: string list) =
{ opts with Arguments = Some args}

[<CustomOperation("workingDirectory")>]
member inline this.WorkingDirectory(opts, workingDirectory: string) =
///<summary>The arguments to call the binary with</summary>
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
/// <param name="arguments">The arguments to call the binary with</param>
[<CustomOperation("arguments")>]
member this.Arguments(opts, [<ParamArray>] arguments: string array) =
{ opts with Arguments = Some (arguments |> List.ofArray) }

///<summary>The arguments to call the binary with</summary>
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
/// <param name="arguments">The arguments to call the binary with</param>
[<CustomOperation("arguments")>]
member this.Arguments(opts, arguments: string list) =
{ opts with Arguments = Some arguments}

///<summary>Specify a working directory to start the execution of the binary in</summary>
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
/// <param name="workingDirectory">Specify a working directory to start the execution of the binary in</param>
[<CustomOperation("working_dir")>]
member this.WorkingDirectory(opts, workingDirectory: string) =
{ opts with WorkingDirectory = Some workingDirectory }

[<CustomOperation("env")>]
member inline this.EnvironmentVariables(opts, env: Map<string, string>) =
member this.EnvironmentVariables(opts, env: Map<string, string>) =
{ opts with Environment = Some env }

[<CustomOperation("timeout")>]
member inline this.Timeout(opts, timeout) =
member this.Timeout(opts, timeout) =
{ opts with Timeout = Some timeout }

[<CustomOperation("stream_reader_wait_timeout")>]
member inline this.WaitForStreamReadersTimeout(opts, timeout) =
member this.WaitForStreamReadersTimeout(opts, timeout) =
{ opts with WaitForStreamReadersTimeout = Some timeout }

[<CustomOperation("send_control_c")>]
member inline this.SendControlCFirst(opts, sendControlCFirst) =
member this.SendControlCFirst(opts, sendControlCFirst) =
{ opts with SendControlCFirst = Some sendControlCFirst }

[<CustomOperation("thread_wrap")>]
member inline this.NoWrapInThread(opts, threadWrap) =
member this.NoWrapInThread(opts, threadWrap) =
{ opts with NoWrapInThread = Some (not threadWrap) }

[<CustomOperation("filter_output")>]
member inline this.FilterOutput(opts, find: LineOut -> bool) =
member this.FilterOutput(opts, find: LineOut -> bool) =
{ opts with LineOutFilter = Some find }

[<CustomOperation("validExitCode")>]
member inline this.ValidExitCode(opts, exitCodeClassifier: int -> bool) =
member this.ValidExitCode(opts, exitCodeClassifier: int -> bool) =
{ opts with ValidExitCodeClassifier = Some exitCodeClassifier }

[<CustomOperation("find")>]
Expand All @@ -163,43 +235,26 @@ type ExecBuilder() =
Proc.Start(startArguments)

[<CustomOperation("run_args")>]
member this.InvokeArgs(opts, [<ParamArray>] args: string array) =
let opts = { opts with Arguments = Some (args |> List.ofArray) }
member this.InvokeArgs(opts, [<ParamArray>] arguments: string array) =
let opts = { opts with Arguments = Some (arguments |> List.ofArray) }
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

[<CustomOperation("run_args")>]
member this.InvokeArgs(opts, args: string list) =
let opts = { opts with Arguments = Some args}
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

[<CustomOperation("run")>]
member this.Execute(opts) =
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

[<CustomOperation("run")>]
member this.Execute(opts, binary, args: string list) =
let opts = { opts with Binary = binary; Arguments = Some args}
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

[<CustomOperation("run")>]
member this.Execute(opts, binary, [<ParamArray>] args: string array) =
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
member this.InvokeArgs(opts, arguments: string list) =
let opts = { opts with Arguments = Some arguments}
let execArgs = execArgs opts
Proc.Exec(execArgs) |> ignore

[<CustomOperation("exit_code_of")>]
member this.ReturnStatus(opts, binary, args: string list) =
let opts = { opts with Binary = binary; Arguments = Some args}
member this.ReturnStatus(opts, binary, arguments: string list) =
let opts = { opts with Binary = binary; Arguments = Some arguments}
let execArgs = execArgs opts
Proc.Exec(execArgs).GetValueOrDefault 1

[<CustomOperation("exit_code_of")>]
member this.ReturnStatus(opts, binary, [<ParamArray>] args: string array) =
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
member this.ReturnStatus(opts, binary, [<ParamArray>] arguments: string array) =
let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)}
let execArgs = execArgs opts
Proc.Exec(execArgs).GetValueOrDefault 1

Expand All @@ -209,16 +264,16 @@ type ExecBuilder() =
Proc.Exec(execArgs).GetValueOrDefault 1

[<CustomOperation("output_of")>]
member this.ReturnOutput(opts, binary, [<ParamArray>] args: string array) =
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
member this.ReturnOutput(opts, binary, [<ParamArray>] arguments: string array) =
let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)}
let execArgs = startArgs opts
Proc.Start(execArgs)

[<CustomOperation("output_of")>]
member this.ReturnOutput(opts) =
let startArgs = startArgs opts
Proc.Start(startArgs)


let exec = ExecBuilder()

Expand Down
8 changes: 4 additions & 4 deletions src/Proc.Fs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ you can supply the following options.
```fsharp
exec {
binary "dotnet"
args "--help"
arguments "--help"
env Map[("key", "value")]
workingDirectory "."
send_control_c false
Expand All @@ -74,7 +74,7 @@ Shortcut to supply arguments AND run
```fsharp
let linesContainingClean = exec {
binary "dotnet"
args "--help"
arguments "--help"
filter (fun l -> l.Line.Contains "clean")
}
```
Expand All @@ -86,7 +86,7 @@ run the process returning only the console out matching the `filter` if you want
let dotnetHelpExitCode = exec {
binary "dotnet"
args "--help"
arguments "--help"
exit_code
}
```
Expand All @@ -97,7 +97,7 @@ returns just the exit code
let helpOutput = exec {
binary "dotnet"
args "--help"
arguments "--help"
output
}
```
Expand Down

0 comments on commit 9213de6

Please sign in to comment.