22
33open System
44open System.IO
5+ open Elastic.Managed .ConsoleWriters
56open ProcNet
6- open Fake.IO .Globbing .Operators
77open ProcNet.Std
88
99module Tooling =
1010
11- type ExecResult = { ExitCode: int option ; Output: Std .LineOut seq ;}
11+ type ExecResult = { ExitCode: int ; Output: Std .LineOut seq ;}
1212
1313 let private defaultTimeout = TimeSpan.FromMinutes( 5. )
1414
15+ let startRedirectedInWithTimeout timeout workinDir bin args =
16+ let startArgs = StartArguments( bin, args |> List.toArray)
17+ if ( Option.isSome workinDir) then
18+ startArgs.WorkingDirectory <- Option.defaultValue " " workinDir
19+ if Commandline.isMono then startArgs.WaitForStreamReadersTimeout <- Nullable< TimeSpan>()
20+ let result = Proc.StartRedirected( startArgs, timeout, LineHighlightWriter())
21+ if not result.Completed then failwithf " process failed to complete within %O : %s " timeout bin
22+ if not result.ExitCode.HasValue then failwithf " process yielded no exit code: %s " bin
23+ { ExitCode = result.ExitCode.Value; Output = seq []}
24+
1525 let readInWithTimeout timeout workinDir bin args =
1626 let startArgs = StartArguments( bin, args |> List.toArray)
1727 if ( Option.isSome workinDir) then
1828 startArgs.WorkingDirectory <- Option.defaultValue " " workinDir
1929 let result = Proc.Start( startArgs, timeout, ConsoleOutColorWriter())
2030 if not result.Completed then failwithf " process failed to complete within %O : %s " timeout bin
21- let exitCode = match result.ExitCode.HasValue with | false -> None | true -> Some result.ExitCode.Value
22- { ExitCode = exitCode ; Output = seq result.ConsoleOut}
31+ if not result.ExitCode.HasValue then failwithf " process yielded no exit code: %s " bin
32+ { ExitCode = result.ExitCode.Value ; Output = seq result.ConsoleOut}
2333
2434 let read bin args = readInWithTimeout defaultTimeout None bin args
2535
@@ -41,6 +51,8 @@ module Tooling =
4151 type BuildTooling ( timeout , path ) =
4252 let timeout = match timeout with | Some t -> t | None -> defaultTimeout
4353 member this.Path = path
54+ member this.StartInWithTimeout workingDirectory arguments timeout = startRedirectedInWithTimeout timeout ( Some workingDirectory) this.Path arguments
55+ member this.ReadInWithTimeout workingDirectory arguments timeout = readInWithTimeout timeout ( Some workingDirectory) this.Path arguments
4456 member this.ExecInWithTimeout workingDirectory arguments timeout = execInWithTimeout timeout ( Some workingDirectory) this.Path arguments
4557 member this.ExecWithTimeout arguments timeout = execInWithTimeout timeout None this.Path arguments
4658 member this.ExecIn workingDirectory arguments = this.ExecInWithTimeout workingDirectory arguments timeout
0 commit comments