From 53b5719cc59c8c20b5bf9a4f1ef8c8f99426aca1 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Sun, 7 Jan 2024 15:28:58 +0100 Subject: [PATCH 1/3] args is too common to use as common expression --- examples/ScratchPad.Fs/Program.fs | 30 +++++-- src/Proc.Fs/Bindings.fs | 127 +++++++++++++++++++++--------- src/Proc.Fs/README.md | 8 +- 3 files changed, 117 insertions(+), 48 deletions(-) diff --git a/examples/ScratchPad.Fs/Program.fs b/examples/ScratchPad.Fs/Program.fs index a434009..b68f6b4 100644 --- a/examples/ScratchPad.Fs/Program.fs +++ b/examples/ScratchPad.Fs/Program.fs @@ -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 @@ -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" " "} diff --git a/src/Proc.Fs/Bindings.fs b/src/Proc.Fs/Bindings.fs index 367ce27..ef96763 100644 --- a/src/Proc.Fs/Bindings.fs +++ b/src/Proc.Fs/Bindings.fs @@ -52,7 +52,7 @@ type ShellBuilder() = member t.Yield _ = ExecOptions.Empty - [] + [] member inline this.WorkingDirectory(opts, workingDirectory: string) = { opts with WorkingDirectory = Some workingDirectory } @@ -90,54 +90,126 @@ type ShellBuilder() = Proc.Exec(execArgs) |> ignore opts + let shell = ShellBuilder() +type TempBuilder() = + + member t.Yield _ = ExecOptions.Empty + + [] + member this.Run2(opts, binary, [] args: string array) = + let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)} + let execArgs = execArgs opts + Proc.Exec(execArgs) |> ignore + + [] + 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 + + [] + member this.Run2(opts) = + let execArgs = execArgs opts + Proc.Exec(execArgs) |> ignore + +let temp = TempBuilder() + + type ExecBuilder() = member t.Yield _ = ExecOptions.Empty + ///Runs using immediately + /// the computation build thus far, not specified directly + /// The binary to execute + /// the arguments to pass on to the binary being executed + [] + member this.Execute(opts, binary, [] arguments: string array) = + let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)} + let execArgs = execArgs opts + Proc.Exec(execArgs) |> ignore + + ///Runs using immediately + /// the computation build thus far, not specified directly + /// The binary to execute + /// the arguments to pass on to the binary being executed + [] + 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 + + /// + /// Runs the the computation build thus far. + /// Needs at least `binary` to be specified + /// + [] + member this.Execute(opts) = + if opts.Binary = "" then failwithf "No binary specified to exec computation expression" + let execArgs = execArgs opts + Proc.Exec(execArgs) |> ignore + + ///Supply external to bootstrap + [] + member this.Options(_, reuseOptions: ExecOptions) = + reuseOptions + + ///The binary to execute + /// the computation build thus far, not specified directly + /// The binary to execute [] member this.Binary(opts, binary) = { opts with Binary = binary } - [] - member inline this.Arguments(opts, [] args: string array) = - { opts with Arguments = Some (args |> List.ofArray) } - - [] - member inline this.Arguments(opts, args: string list) = - { opts with Arguments = Some args} - - [] - member inline this.WorkingDirectory(opts, workingDirectory: string) = + ///The arguments to call the binary with + /// the computation build thus far, not specified directly + /// The arguments to call the binary with + [] + member this.Arguments(opts, [] arguments: string array) = + { opts with Arguments = Some (arguments |> List.ofArray) } + + ///The arguments to call the binary with + /// the computation build thus far, not specified directly + /// The arguments to call the binary with + [] + member this.Arguments(opts, arguments: string list) = + { opts with Arguments = Some arguments} + + ///Specify a working directory to start the execution of the binary in + /// the computation build thus far, not specified directly + /// Specify a working directory to start the execution of the binary in + [] + member this.WorkingDirectory(opts, workingDirectory: string) = { opts with WorkingDirectory = Some workingDirectory } [] - member inline this.EnvironmentVariables(opts, env: Map) = + member this.EnvironmentVariables(opts, env: Map) = { opts with Environment = Some env } [] - member inline this.Timeout(opts, timeout) = + member this.Timeout(opts, timeout) = { opts with Timeout = Some timeout } [] - member inline this.WaitForStreamReadersTimeout(opts, timeout) = + member this.WaitForStreamReadersTimeout(opts, timeout) = { opts with WaitForStreamReadersTimeout = Some timeout } [] - member inline this.SendControlCFirst(opts, sendControlCFirst) = + member this.SendControlCFirst(opts, sendControlCFirst) = { opts with SendControlCFirst = Some sendControlCFirst } [] - member inline this.NoWrapInThread(opts, threadWrap) = + member this.NoWrapInThread(opts, threadWrap) = { opts with NoWrapInThread = Some (not threadWrap) } [] - member inline this.FilterOutput(opts, find: LineOut -> bool) = + member this.FilterOutput(opts, find: LineOut -> bool) = { opts with LineOutFilter = Some find } [] - member inline this.ValidExitCode(opts, exitCodeClassifier: int -> bool) = + member this.ValidExitCode(opts, exitCodeClassifier: int -> bool) = { opts with ValidExitCodeClassifier = Some exitCodeClassifier } [] @@ -174,23 +246,6 @@ type ExecBuilder() = let execArgs = execArgs opts Proc.Exec(execArgs) |> ignore - [] - member this.Execute(opts) = - let execArgs = execArgs opts - Proc.Exec(execArgs) |> ignore - - [] - 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 - - [] - member this.Execute(opts, binary, [] args: string array) = - let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)} - let execArgs = execArgs opts - Proc.Exec(execArgs) |> ignore - [] member this.ReturnStatus(opts, binary, args: string list) = let opts = { opts with Binary = binary; Arguments = Some args} @@ -218,7 +273,7 @@ type ExecBuilder() = member this.ReturnOutput(opts) = let startArgs = startArgs opts Proc.Start(startArgs) - + let exec = ExecBuilder() diff --git a/src/Proc.Fs/README.md b/src/Proc.Fs/README.md index fdf6f61..2a7d1ad 100644 --- a/src/Proc.Fs/README.md +++ b/src/Proc.Fs/README.md @@ -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 @@ -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") } ``` @@ -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 } ``` @@ -97,7 +97,7 @@ returns just the exit code let helpOutput = exec { binary "dotnet" - args "--help" + arguments "--help" output } ``` From 5e3a1a5af2d8163d210c5804c7e1afd219ed4200 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Sun, 7 Jan 2024 15:30:03 +0100 Subject: [PATCH 2/3] rename more arguments --- src/Proc.Fs/Bindings.fs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Proc.Fs/Bindings.fs b/src/Proc.Fs/Bindings.fs index ef96763..1858915 100644 --- a/src/Proc.Fs/Bindings.fs +++ b/src/Proc.Fs/Bindings.fs @@ -235,26 +235,26 @@ type ExecBuilder() = Proc.Start(startArguments) [] - member this.InvokeArgs(opts, [] args: string array) = - let opts = { opts with Arguments = Some (args |> List.ofArray) } + member this.InvokeArgs(opts, [] arguments: string array) = + let opts = { opts with Arguments = Some (arguments |> List.ofArray) } let execArgs = execArgs opts Proc.Exec(execArgs) |> ignore [] - member this.InvokeArgs(opts, args: string list) = - let opts = { opts with Arguments = Some args} + member this.InvokeArgs(opts, arguments: string list) = + let opts = { opts with Arguments = Some arguments} let execArgs = execArgs opts Proc.Exec(execArgs) |> ignore [] - 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 [] - member this.ReturnStatus(opts, binary, [] args: string array) = - let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)} + member this.ReturnStatus(opts, binary, [] arguments: string array) = + let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)} let execArgs = execArgs opts Proc.Exec(execArgs).GetValueOrDefault 1 @@ -264,8 +264,8 @@ type ExecBuilder() = Proc.Exec(execArgs).GetValueOrDefault 1 [] - member this.ReturnOutput(opts, binary, [] args: string array) = - let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)} + member this.ReturnOutput(opts, binary, [] arguments: string array) = + let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)} let execArgs = startArgs opts Proc.Start(execArgs) From 1028c989364c7fd256069e9ddff0c017d9eef306 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Sun, 7 Jan 2024 15:33:43 +0100 Subject: [PATCH 3/3] fix pushes hopefully --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2dc9ad1..8c0c353 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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')