Skip to content

Commit 9213de6

Browse files
authored
args is too common to use as common expression (#10)
* args is too common to use as common expression * rename more arguments * fix pushes hopefully
1 parent 4a906e7 commit 9213de6

File tree

4 files changed

+129
-60
lines changed

4 files changed

+129
-60
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
if: github.event_name == 'push' && startswith(github.ref, 'refs/heads')
5050
shell: bash
5151
run: |
52-
until dotnet nuget push build/output/*.nupkg -k ${{secrets.GITHUB_TOKEN}} --skip-duplicate --no-symbols true; do echo "Retrying"; sleep 1; done;
52+
until dotnet nuget push 'build/output/*.nupkg' -k ${{secrets.GITHUB_TOKEN}} --skip-duplicate --no-symbols; do echo "Retrying"; sleep 1; done;
5353
5454
- run: ./build.sh generatereleasenotes -s true
5555
name: Generate release notes for tag
@@ -58,6 +58,6 @@ jobs:
5858
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags')
5959
name: Create or update release for tag on github
6060

61-
- 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
61+
- 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
6262
name: release to nuget.org
6363
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags')

examples/ScratchPad.Fs/Program.fs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@ let _ = shell {
66
exec "uname"
77
}
88

9+
let a: string list = [""]
10+
temp { run }
11+
temp { run "x" }
12+
temp { run "x" "x" }
13+
temp { run "x" [] }
14+
temp { run "x" a }
15+
916
let dotnetVersion = exec {
1017
binary "dotnet"
11-
args "--help"
18+
arguments "--help"
1219
filter_output (fun l -> l.Line.Contains "clean")
1320
filter (fun l -> l.Line.Contains "clean")
1421
}
1522

23+
printfn "Found lines %i" dotnetVersion.Length
24+
25+
1626
exec {
1727
binary "dotnet"
18-
args "--help"
28+
arguments "--help"
1929
env Map[("key", "value")]
20-
workingDirectory "."
30+
working_dir "."
2131
send_control_c false
2232
timeout (TimeSpan.FromSeconds(10))
2333
thread_wrap false
@@ -27,22 +37,26 @@ exec {
2737

2838
let helpStatus = exec {
2939
binary "dotnet"
30-
args "--help"
40+
arguments "--help"
3141
exit_code
3242
}
3343

3444
let helpOutput = exec {
3545
binary "dotnet"
36-
args "--help"
46+
arguments "--help"
3747
output
3848
}
3949

40-
printfn "Found lines %i" dotnetVersion.Length
50+
let dotnet = exec { binary "dotnet" }
4151

42-
exec {
43-
binary "dotnet"
52+
let x = exec {
53+
options dotnet
4454
run_args ["restore"; "--help"]
4555
}
4656

57+
let args: string list = [""]
4758
exec { run "dotnet" " "}
59+
exec { run "dotnet" args }
60+
61+
let _ = shell { exec "dotnet" a }
4862
let statusCode = exec { exit_code_of "dotnet" " "}

src/Proc.Fs/Bindings.fs

Lines changed: 101 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type ShellBuilder() =
5252

5353
member t.Yield _ = ExecOptions.Empty
5454

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

@@ -90,54 +90,126 @@ type ShellBuilder() =
9090
Proc.Exec(execArgs) |> ignore
9191
opts
9292

93+
9394
let shell = ShellBuilder()
9495

96+
type TempBuilder() =
97+
98+
member t.Yield _ = ExecOptions.Empty
99+
100+
[<CustomOperation("run")>]
101+
member this.Run2(opts, binary, [<ParamArray>] args: string array) =
102+
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
103+
let execArgs = execArgs opts
104+
Proc.Exec(execArgs) |> ignore
105+
106+
[<CustomOperation("run")>]
107+
member this.Run2(opts, binary, args: string list) =
108+
let opts = { opts with Binary = binary; Arguments = Some args}
109+
let execArgs = execArgs opts
110+
Proc.Exec(execArgs) |> ignore
111+
112+
[<CustomOperation("run")>]
113+
member this.Run2(opts) =
114+
let execArgs = execArgs opts
115+
Proc.Exec(execArgs) |> ignore
116+
117+
let temp = TempBuilder()
118+
119+
95120
type ExecBuilder() =
96121

97122
member t.Yield _ = ExecOptions.Empty
98123

124+
///<summary>Runs <paramref name="binary"/> using <paramref name="arguments"/> immediately</summary>
125+
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
126+
/// <param name="binary">The binary to execute</param>
127+
/// <param name="arguments">the arguments to pass on to the binary being executed</param>
128+
[<CustomOperation("run")>]
129+
member this.Execute(opts, binary, [<ParamArray>] arguments: string array) =
130+
let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)}
131+
let execArgs = execArgs opts
132+
Proc.Exec(execArgs) |> ignore
133+
134+
///<summary>Runs <paramref name="binary"/> using <paramref name="arguments"/> immediately</summary>
135+
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
136+
/// <param name="binary">The binary to execute</param>
137+
/// <param name="arguments">the arguments to pass on to the binary being executed</param>
138+
[<CustomOperation("run")>]
139+
member this.Execute(opts, binary, arguments: string list) =
140+
let opts = { opts with Binary = binary; Arguments = Some arguments}
141+
let execArgs = execArgs opts
142+
Proc.Exec(execArgs) |> ignore
143+
144+
///<summary>
145+
/// Runs the <see cref="ExecOptions"/> the computation build thus far.
146+
/// <para>Needs at least `binary` to be specified</para>
147+
/// </summary>
148+
[<CustomOperation("run")>]
149+
member this.Execute(opts) =
150+
if opts.Binary = "" then failwithf "No binary specified to exec computation expression"
151+
let execArgs = execArgs opts
152+
Proc.Exec(execArgs) |> ignore
153+
154+
///<summary>Supply external <see cref="ExecOptions"/> to bootstrap</summary>
155+
[<CustomOperation("options")>]
156+
member this.Options(_, reuseOptions: ExecOptions) =
157+
reuseOptions
158+
159+
///<summary>The binary to execute</summary>
160+
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
161+
/// <param name="binary">The binary to execute</param>
99162
[<CustomOperation("binary")>]
100163
member this.Binary(opts, binary) =
101164
{ opts with Binary = binary }
102165

103-
[<CustomOperation("args")>]
104-
member inline this.Arguments(opts, [<ParamArray>] args: string array) =
105-
{ opts with Arguments = Some (args |> List.ofArray) }
106-
107-
[<CustomOperation("args")>]
108-
member inline this.Arguments(opts, args: string list) =
109-
{ opts with Arguments = Some args}
110-
111-
[<CustomOperation("workingDirectory")>]
112-
member inline this.WorkingDirectory(opts, workingDirectory: string) =
166+
///<summary>The arguments to call the binary with</summary>
167+
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
168+
/// <param name="arguments">The arguments to call the binary with</param>
169+
[<CustomOperation("arguments")>]
170+
member this.Arguments(opts, [<ParamArray>] arguments: string array) =
171+
{ opts with Arguments = Some (arguments |> List.ofArray) }
172+
173+
///<summary>The arguments to call the binary with</summary>
174+
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
175+
/// <param name="arguments">The arguments to call the binary with</param>
176+
[<CustomOperation("arguments")>]
177+
member this.Arguments(opts, arguments: string list) =
178+
{ opts with Arguments = Some arguments}
179+
180+
///<summary>Specify a working directory to start the execution of the binary in</summary>
181+
/// <param name="opts"><see cref="ExecOptions"/> the computation build thus far, not specified directly</param>
182+
/// <param name="workingDirectory">Specify a working directory to start the execution of the binary in</param>
183+
[<CustomOperation("working_dir")>]
184+
member this.WorkingDirectory(opts, workingDirectory: string) =
113185
{ opts with WorkingDirectory = Some workingDirectory }
114186

115187
[<CustomOperation("env")>]
116-
member inline this.EnvironmentVariables(opts, env: Map<string, string>) =
188+
member this.EnvironmentVariables(opts, env: Map<string, string>) =
117189
{ opts with Environment = Some env }
118190

119191
[<CustomOperation("timeout")>]
120-
member inline this.Timeout(opts, timeout) =
192+
member this.Timeout(opts, timeout) =
121193
{ opts with Timeout = Some timeout }
122194

123195
[<CustomOperation("stream_reader_wait_timeout")>]
124-
member inline this.WaitForStreamReadersTimeout(opts, timeout) =
196+
member this.WaitForStreamReadersTimeout(opts, timeout) =
125197
{ opts with WaitForStreamReadersTimeout = Some timeout }
126198

127199
[<CustomOperation("send_control_c")>]
128-
member inline this.SendControlCFirst(opts, sendControlCFirst) =
200+
member this.SendControlCFirst(opts, sendControlCFirst) =
129201
{ opts with SendControlCFirst = Some sendControlCFirst }
130202

131203
[<CustomOperation("thread_wrap")>]
132-
member inline this.NoWrapInThread(opts, threadWrap) =
204+
member this.NoWrapInThread(opts, threadWrap) =
133205
{ opts with NoWrapInThread = Some (not threadWrap) }
134206

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

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

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

165237
[<CustomOperation("run_args")>]
166-
member this.InvokeArgs(opts, [<ParamArray>] args: string array) =
167-
let opts = { opts with Arguments = Some (args |> List.ofArray) }
238+
member this.InvokeArgs(opts, [<ParamArray>] arguments: string array) =
239+
let opts = { opts with Arguments = Some (arguments |> List.ofArray) }
168240
let execArgs = execArgs opts
169241
Proc.Exec(execArgs) |> ignore
170242

171243
[<CustomOperation("run_args")>]
172-
member this.InvokeArgs(opts, args: string list) =
173-
let opts = { opts with Arguments = Some args}
174-
let execArgs = execArgs opts
175-
Proc.Exec(execArgs) |> ignore
176-
177-
[<CustomOperation("run")>]
178-
member this.Execute(opts) =
179-
let execArgs = execArgs opts
180-
Proc.Exec(execArgs) |> ignore
181-
182-
[<CustomOperation("run")>]
183-
member this.Execute(opts, binary, args: string list) =
184-
let opts = { opts with Binary = binary; Arguments = Some args}
185-
let execArgs = execArgs opts
186-
Proc.Exec(execArgs) |> ignore
187-
188-
[<CustomOperation("run")>]
189-
member this.Execute(opts, binary, [<ParamArray>] args: string array) =
190-
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
244+
member this.InvokeArgs(opts, arguments: string list) =
245+
let opts = { opts with Arguments = Some arguments}
191246
let execArgs = execArgs opts
192247
Proc.Exec(execArgs) |> ignore
193248

194249
[<CustomOperation("exit_code_of")>]
195-
member this.ReturnStatus(opts, binary, args: string list) =
196-
let opts = { opts with Binary = binary; Arguments = Some args}
250+
member this.ReturnStatus(opts, binary, arguments: string list) =
251+
let opts = { opts with Binary = binary; Arguments = Some arguments}
197252
let execArgs = execArgs opts
198253
Proc.Exec(execArgs).GetValueOrDefault 1
199254

200255
[<CustomOperation("exit_code_of")>]
201-
member this.ReturnStatus(opts, binary, [<ParamArray>] args: string array) =
202-
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
256+
member this.ReturnStatus(opts, binary, [<ParamArray>] arguments: string array) =
257+
let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)}
203258
let execArgs = execArgs opts
204259
Proc.Exec(execArgs).GetValueOrDefault 1
205260

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

211266
[<CustomOperation("output_of")>]
212-
member this.ReturnOutput(opts, binary, [<ParamArray>] args: string array) =
213-
let opts = { opts with Binary = binary; Arguments = Some (args |> List.ofArray)}
267+
member this.ReturnOutput(opts, binary, [<ParamArray>] arguments: string array) =
268+
let opts = { opts with Binary = binary; Arguments = Some (arguments |> List.ofArray)}
214269
let execArgs = startArgs opts
215270
Proc.Start(execArgs)
216271

217272
[<CustomOperation("output_of")>]
218273
member this.ReturnOutput(opts) =
219274
let startArgs = startArgs opts
220275
Proc.Start(startArgs)
221-
276+
222277

223278
let exec = ExecBuilder()
224279

src/Proc.Fs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ you can supply the following options.
4747
```fsharp
4848
exec {
4949
binary "dotnet"
50-
args "--help"
50+
arguments "--help"
5151
env Map[("key", "value")]
5252
workingDirectory "."
5353
send_control_c false
@@ -74,7 +74,7 @@ Shortcut to supply arguments AND run
7474
```fsharp
7575
let linesContainingClean = exec {
7676
binary "dotnet"
77-
args "--help"
77+
arguments "--help"
7878
filter (fun l -> l.Line.Contains "clean")
7979
}
8080
```
@@ -86,7 +86,7 @@ run the process returning only the console out matching the `filter` if you want
8686
8787
let dotnetHelpExitCode = exec {
8888
binary "dotnet"
89-
args "--help"
89+
arguments "--help"
9090
exit_code
9191
}
9292
```
@@ -97,7 +97,7 @@ returns just the exit code
9797
9898
let helpOutput = exec {
9999
binary "dotnet"
100-
args "--help"
100+
arguments "--help"
101101
output
102102
}
103103
```

0 commit comments

Comments
 (0)