Nuke.Cola
Loading...
Searching...
No Matches
ToolCola.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using Nuke.Common;
7using Nuke.Common.IO;
8using Nuke.Common.Tooling;
9using Nuke.Common.Utilities;
10using Serilog;
11
12namespace Nuke.Cola.Tooling;
13
14public static class ToolCola
15{
16 /// <summary>
17 /// A tool output logger which doesn't treat standard error as error logs. Many tools for example send progress
18 /// information to standard-error which shouldn't be treated as a real error or warning.
19 /// </summary>
20 /// <param name="type"></param>
21 /// <param name="output"></param>
22 public static void StdErrorIsNotError(OutputType type, string output) => Log.Debug(output);
23
24 /// <summary>
25 /// Execute a tool with the arguments provided by the input record.
26 /// </summary>
27 /// <param name="tool"></param>
28 /// <param name="args"></param>
29 public static IReadOnlyCollection<Output> ExecuteWith(this Tool tool, ToolArguments args)
30 => tool(
31 $"{args.Arguments:nq}",
32 args.WorkingDirectory,
33 args.EnvironmentVariables,
34 args.Timeout,
35 args.LogOutput,
36 args.LogInvocation,
37 args.Logger,
38 args.ExitHandler
39 );
40
41 /// <summary>
42 /// Execute a tool with standard input with the arguments provided by the input record.
43 /// </summary>
44 /// <param name="tool"></param>
45 /// <param name="args"></param>
46 public static IReadOnlyCollection<Output>? ExecuteWith(this ToolEx tool, ToolExArguments args)
47 => tool(
48 $"{args.ToolArgs.Arguments:nq}",
49 args.ToolArgs.WorkingDirectory,
50 args.ToolArgs.EnvironmentVariables,
51 args.ToolArgs.Timeout,
52 args.ToolArgs.LogOutput,
53 args.ToolArgs.LogInvocation,
54 args.ToolArgs.Logger,
55 args.ToolArgs.ExitHandler,
56 args.Input,
57 args.StandardOutputEncoding,
58 args.StandardInputEncoding
59 );
60
61 /// <summary>
62 /// Set individual Tool launching parameters and propagate the delegate further
63 /// </summary>
64 /// <param name="tool"></param>
65 /// <param name="args"></param>
66 /// <remarks>
67 /// <list>
68 /// <item><term>Arguments </term><description> will be concatenated</description></item>
69 /// <item><term>Working directory </term><description> B overrides the one from A but not when B doesn't have one</description></item>
70 /// <item><term>Environmnent variables </term><description> will be merged</description></item>
71 /// <item><term>TimeOut </term><description> will be maxed</description></item>
72 /// <item><term>LogOutput </term><description> is OR-ed</description></item>
73 /// <item><term>LogInvocation </term><description> is OR-ed</description></item>
74 /// <item><term>Logger / ExitHandler </term><description>A + B is invoked</description></item>
75 /// </list>
76 /// </remarks>
77 public static Tool With(this Tool tool, ToolArguments args)
78 => new PropagateToolExecution(tool, args).Execute;
79
80 /// <summary>
81 /// Set individual Tool launching parameters and propagate the delegate further
82 /// </summary>
83 /// <param name="tool"></param>
84 /// <param name="args"></param>
85 /// <remarks>
86 /// <list>
87 /// <item><term>Arguments </term><description> will be concatenated</description></item>
88 /// <item><term>Working directory </term><description> B overrides the one from A but not when B doesn't have one</description></item>
89 /// <item><term>Environmnent variables </term><description> will be merged</description></item>
90 /// <item><term>TimeOut </term><description> will be maxed</description></item>
91 /// <item><term>LogOutput </term><description> is OR-ed</description></item>
92 /// <item><term>LogInvocation </term><description> is OR-ed</description></item>
93 /// <item><term>Logger / ExitHandler </term><description>A + B is invoked</description></item>
94 /// <item><term>Input </term><description>A + B is invoked</description></item>
95 /// <item><term>Encodings </term><description> B overrides the one from A but not when B doesn't have one</description></item>
96 /// </list>
97 /// </remarks>
98 public static ToolEx With(this ToolEx tool, ToolExArguments args)
99 => new PropagateToolExExecution(tool, args).Execute;
100
101 /// <summary>
102 /// Set individual Tool launching parameters and propagate the delegate further
103 /// </summary>
104 /// <param name="tool"></param>
105 /// <param name="args"></param>
106 /// <remarks>
107 /// <list>
108 /// <item><term>Arguments </term><description> will be concatenated</description></item>
109 /// <item><term>Working directory </term><description> B overrides the one from A but not when B doesn't have one</description></item>
110 /// <item><term>Environmnent variables </term><description> will be merged</description></item>
111 /// <item><term>TimeOut </term><description> will be maxed</description></item>
112 /// <item><term>LogOutput </term><description> is OR-ed</description></item>
113 /// <item><term>LogInvocation </term><description> is OR-ed</description></item>
114 /// <item><term>Logger / ExitHandler </term><description>A + B is invoked</description></item>
115 /// <item><term>Input </term><description> Used from ToolEx arguments</description></item>
116 /// <item><term>Encodings </term><description> Used from ToolEx arguments</description></item>
117 /// </list>
118 /// </remarks>
119 public static ToolEx With(this ToolEx tool, ToolArguments args)
120 => new PropagateToolExExecution(tool, new(args)).Execute;
121
122 /// <summary>
123 /// Set individual Tool launching parameters and propagate the delegate further
124 /// </summary>
125 /// <param name="tool"></param>
126 /// <param name="arguments"></param>
127 /// <param name="workingDirectory"></param>
128 /// <param name="environmentVariables"></param>
129 /// <param name="timeout"></param>
130 /// <param name="logOutput"></param>
131 /// <param name="logInvocation"></param>
132 /// <param name="logger"></param>
133 /// <param name="exitHandler"></param>
134 /// <remarks>
135 /// <list>
136 /// <item><term>Arguments </term><description> will be concatenated</description></item>
137 /// <item><term>Working directory </term><description> B overrides the one from A but not when B doesn't have one</description></item>
138 /// <item><term>Environmnent variables </term><description> will be merged</description></item>
139 /// <item><term>TimeOut </term><description> will be maxed</description></item>
140 /// <item><term>LogOutput </term><description> is OR-ed</description></item>
141 /// <item><term>LogInvocation </term><description> is OR-ed</description></item>
142 /// <item><term>Logger / ExitHandler </term><description>A + B is invoked</description></item>
143 /// </list>
144 /// </remarks>
145 public static Tool With(
146 this Tool tool,
147 ArgumentStringHandlerEx arguments = default,
148 string? workingDirectory = null,
149 IReadOnlyDictionary<string, string>? environmentVariables = null,
150 int? timeout = null,
151 bool? logOutput = null,
152 bool? logInvocation = null,
153 Action<OutputType, string>? logger = null,
154 Action<IProcess>? exitHandler = null
155 ) => tool.With(new ToolArguments(
156 arguments.ToStringAndClear(),
157 workingDirectory,
158 environmentVariables,
159 timeout,
160 logOutput,
161 logInvocation,
162 logger,
163 exitHandler
164 ));
165
166 /// <summary>
167 /// Set individual Tool launching parameters and propagate the delegate further
168 /// </summary>
169 /// <param name="tool"></param>
170 /// <param name="arguments"></param>
171 /// <param name="workingDirectory"></param>
172 /// <param name="environmentVariables"></param>
173 /// <param name="timeout"></param>
174 /// <param name="logOutput"></param>
175 /// <param name="logInvocation"></param>
176 /// <param name="logger"></param>
177 /// <param name="exitHandler"></param>
178 /// <param name="input">Handle standard input stream after process creation</param>
179 /// <param name="standardOutputEncoding">Encoding for standard output. Default is UTF8 (with BOM)</param>
180 /// <param name="standardInputEncoding">Encoding for standard input. Default is UTF8 (without BOM)</param>
181 /// <remarks>
182 /// <list>
183 /// <item><term>Arguments </term><description> will be concatenated</description></item>
184 /// <item><term>Working directory </term><description> B overrides the one from A but not when B doesn't have one</description></item>
185 /// <item><term>Environmnent variables </term><description> will be merged</description></item>
186 /// <item><term>TimeOut </term><description> will be maxed</description></item>
187 /// <item><term>LogOutput </term><description> is OR-ed</description></item>
188 /// <item><term>LogInvocation </term><description> is OR-ed</description></item>
189 /// <item><term>Logger / ExitHandler </term><description>A + B is invoked</description></item>
190 /// <item><term>Input </term><description>A + B is invoked</description></item>
191 /// <item><term>Encodings </term><description> B overrides the one from A but not when B doesn't have one</description></item>
192 /// </list>
193 /// </remarks>
194 public static ToolEx With(
195 this ToolEx tool,
196 ArgumentStringHandlerEx arguments = default,
197 string? workingDirectory = null,
198 IReadOnlyDictionary<string, string>? environmentVariables = null,
199 int? timeout = null,
200 bool? logOutput = null,
201 bool? logInvocation = null,
202 Action<OutputType, string>? logger = null,
203 Action<IProcess>? exitHandler = null,
204 Action<StreamWriter>? input = null,
205 Encoding? standardOutputEncoding = null,
206 Encoding? standardInputEncoding = null
207 ) => tool.With(new ToolExArguments(
208 new(
209 arguments.ToStringAndClear(),
210 workingDirectory,
211 environmentVariables,
212 timeout,
213 logOutput,
214 logInvocation,
215 logger,
216 exitHandler
217 ),
218 input,
219 standardOutputEncoding,
220 standardInputEncoding
221 ));
222
223 /// <summary>
224 /// Mark app output Debug/Info/Warning/Error based on its content rather than the stream
225 /// they were added to.
226 /// </summary>
227 /// <param name="filter"></param>
228 /// <param name="normalOutputLogger"></param>
229 public static ToolArguments SemanticLogging(Func<string, bool>? filter = null, Action<OutputType, string>? normalOutputLogger = null)
230 => new(Logger: (t, l) =>
231 {
232 if (!(filter?.Invoke(l) ?? true)) return;
233
234 if (l.ContainsAnyOrdinalIgnoreCase("success", "complete", "ready", "start", "***"))
235 {
236 Log.Information(l);
237 }
238 else if (l.ContainsOrdinalIgnoreCase("warning"))
239 {
240 Log.Warning(l);
241 }
242 else if (l.ContainsAnyOrdinalIgnoreCase("error", "fail"))
243 {
244 Log.Error(l);
245 }
246 else
247 {
248 if (normalOutputLogger != null)
249 normalOutputLogger(t, l);
250 else
251 {
252 Log.Debug(l);
253 }
254 }
255 });
256
257 /// <summary>
258 /// Mark app output Debug/Info/Warning/Error based on its content rather than the stream
259 /// they were added to.
260 /// </summary>
261 /// <param name="tool"></param>
262 /// <param name="filter"></param>
263 /// <param name="normalOutputLogger"></param>
264 public static Tool WithSemanticLogging(this Tool tool, Func<string, bool>? filter = null, Action<OutputType, string>? normalOutputLogger = null)
265 => tool.With(SemanticLogging(filter, normalOutputLogger));
266
267 /// <summary>
268 /// Mark app output Debug/Info/Warning/Error based on its content rather than the stream
269 /// they were added to.
270 /// </summary>
271 /// <param name="tool"></param>
272 /// <param name="filter"></param>
273 /// <param name="normalOutputLogger"></param>
274 public static ToolEx WithSemanticLogging(this ToolEx tool, Func<string, bool>? filter = null, Action<OutputType, string>? normalOutputLogger = null)
275 => tool.With(SemanticLogging(filter, normalOutputLogger));
276
277 /// <summary>
278 /// ToolArguments for priming environment variables
279 /// </summary>
280 public static ToolArguments CurrentEnvironment => new(EnvironmentVariables: EnvironmentInfo.Variables);
281
282 /// <summary>
283 /// A more comfortable passing of environment variables. This will also pass on parent environment
284 /// </summary>
285 public static ToolArguments EnvVar(string key, object value, bool includeParentEnvironment = true)
286 {
287 var result = includeParentEnvironment
288 ? EnvironmentInfo.Variables.ToDictionary()
289 : new();
290
291 result[key] = value.ToString();
292 return new(EnvironmentVariables: result);
293 }
294
295 /// <summary>
296 /// A more comfortable passing of environment variables. This will also pass on parent environment
297 /// </summary>
298 public static ToolArguments EnvVars(bool includeParentEnvironment, params (string key, object value)[] items)
299 {
300 var parent = includeParentEnvironment
301 ? EnvironmentInfo.Variables.ToDictionary()
302 : null;
303 var itemsDict = items.ToDictionary(i => i.key, i => i.value!.ToString()!);
304 return new(EnvironmentVariables: parent.Merge(itemsDict));
305 }
306
307 /// <summary>
308 /// A more comfortable passing of environment variables. This will also pass on parent environment
309 /// </summary>
310 public static ToolArguments EnvVars(params (string key, object value)[] items) => EnvVars(true, items);
311
312 /// <summary>
313 /// A more comfortable passing of environment variables. This will also pass on parent environment
314 /// </summary>
315 public static Tool WithEnvVar(this Tool tool, string key, object value, bool includeParentEnvironment = true)
316 => tool.With(EnvVar(key, value, includeParentEnvironment));
317
318 /// <summary>
319 /// A more comfortable passing of environment variables. This will also pass on parent environment
320 /// </summary>
321 public static Tool WithEnvVars(this Tool tool, bool includeParentEnvironment, params (string key, object value)[] items)
322 => tool.With(EnvVars(includeParentEnvironment, items));
323
324 /// <summary>
325 /// A more comfortable passing of environment variables. This will also pass on parent environment
326 /// </summary>
327 public static Tool WithEnvVars(this Tool tool, params (string key, object value)[] items)
328 => tool.With(EnvVars(items));
329
330 /// <summary>
331 /// Add an input path to this tool's PATH list. It won't be added if input path is already in there.
332 /// </summary>
333 public static Tool WithPathVar(this Tool tool, AbsolutePath path)
334 => tool.WithEnvVar(
335 "PATH",
336 EnvironmentInfo.Paths.Union([ path.ToString() ]).JoinSemicolon()
337 );
338
339 /// <summary>
340 /// A more comfortable passing of environment variables. This will also pass on parent environment
341 /// </summary>
342 public static ToolEx WithEnvVar(this ToolEx tool, string key, object value, bool includeParentEnvironment = true)
343 => tool.With(EnvVar(key, value, includeParentEnvironment));
344
345 /// <summary>
346 /// A more comfortable passing of environment variables. This will also pass on parent environment
347 /// </summary>
348 public static ToolEx WithEnvVars(this ToolEx tool, params (string key, object value)[] items)
349 => tool.With(EnvVars(items));
350
351 /// <summary>
352 /// A more comfortable passing of environment variables. This will also pass on parent environment
353 /// </summary>
354 public static ToolEx WithEnvVars(this ToolEx tool, bool includeParentEnvironment, params (string key, object value)[] items)
355 => tool.With(EnvVars(includeParentEnvironment, items));
356
357 /// <summary>
358 /// Add an input path to this tool's PATH list. It won't be added if input path is already in there.
359 /// </summary>
360 public static ToolEx WithPathVar(this ToolEx tool, AbsolutePath path)
361 => tool.WithEnvVar(
362 "PATH",
363 EnvironmentInfo.Paths.Union([ path.ToString() ]).JoinSemicolon()
364 );
365
366 /// <summary>
367 /// Removes ANSI escape sequences from the output of a Tool (remove color data for example)
368 /// </summary>
369 public static IEnumerable<Output> RemoveAnsiEscape(this IEnumerable<Output> toolOutput)
370 => toolOutput.Select(l => new Output
371 {
372 Type = l.Type,
373 Text = l.Text.ReplaceRegex("\x1b\\[[0-9;]*[mK]", m => "")
374 });
375
376 /// <summary>
377 /// Pipe the results of a tool into the standard input of the next tool. This is not exactly the same as real
378 /// command line piping, the previous process needs to be finished first to pipe its output into the next one.
379 /// This however gives the opportunity to transform / filter the output of previous tool with regular LINQ
380 /// before passing it to the next one.
381 /// </summary>
382 /// <param name="previous">The output of a previous program</param>
383 /// <param name="next">Initial tool delegate of the next program</param>
384 /// <param name="pipeError">Also pipe standard-error into next program</param>
385 /// <param name="close">
386 /// If this is true, close the input stream after all the lines have been written. This is set to true by
387 /// default for ease of usage, as most of the time a program's output is the only thing needed to be passed to
388 /// another program. However if false don't forget to queue closing the input stream with CloseInput.
389 /// </param>
390 /// <returns>A composite ToolEx delegate</returns>
391 public static ToolEx Pipe(this IEnumerable<Output> previous, ToolEx next, bool pipeError = false, bool close = true)
392 => next.With(input: s =>
393 {
394 foreach (var line in previous)
395 {
396 if (line.Type == OutputType.Std || pipeError)
397 s.WriteLine(line.Text);
398 }
399 if (close) s.Close();
400 });
401
402 /// <summary>
403 /// Provide lines for standard input once the program is run. If the target program waits until end-of-stream
404 /// queue closing the input stream with CloseInput.
405 /// </summary>
406 /// <param name="tool"></param>
407 /// <param name="lines"></param>
408 public static ToolEx WithInput(this ToolEx tool, IEnumerable<string> lines)
409 => tool.With(input: s =>
410 {
411 foreach (var line in lines)
412 s.WriteLine(line);
413 });
414
415 /// <summary>
416 /// Provide a single line for standard input once the program is run.
417 /// </summary>
418 /// <param name="tool"></param>
419 /// <param name="line"></param>
420 public static ToolEx WithInput(this ToolEx tool, string line)
421 => tool.With(input: s => s.WriteLine(line));
422
423 /// <summary>
424 /// Explicitly close the standard input after other inputs have been queued. Some programs may freeze without
425 /// this step.
426 /// </summary>
427 /// <param name="tool"></param>
428 public static ToolEx CloseInput(this ToolEx tool) => tool.With(input: s => s.Close());
429
430 /// <summary>
431 /// Attempt to update PATH of this process from user's environment variables
432 /// </summary>
433 public static void UpdatePathEnvVar()
434 {
435 if (!EnvironmentInfo.IsWin) return;
436 var processPaths = EnvironmentInfo.Paths;
437 var userPaths = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User)!.Split(';');
438 var machinePaths = Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine)!.Split(';');
439
440 var result = processPaths.Union(userPaths).Union(machinePaths).JoinSemicolon();
441 Environment.SetEnvironmentVariable("PATH", result);
442 }
443
444 /// <summary>
445 /// Get a tool which should be in PATH, and provide an optional way to set it up automatically if it wasn't
446 /// </summary>
447 /// <returns>The Tool or an error if it wasn't in PATH and the setup had failed</returns>
448 public static ValueOrError<Tool> Use(string tool, Action? setup = null)
449 => ErrorHandling.TryGet(() => ToolResolver.GetPathTool(tool))
450 .Else(setup != null, () =>
451 {
452 Log.Warning($"{tool} was not installed, but it's OK we're installing it now.");
453 setup!();
455 return ToolResolver.GetPathTool(tool);
456 });
457
458 /// <summary>
459 /// Try a different setup method for a Tool which may failed its installation
460 /// </summary>
461 /// <param name="result">Result of the previous attempt</param>
462 /// <param name="condition">Only attempt this method of setup when condition is met</param>
463 /// <param name="tool">The name of the tool</param>
464 /// <param name="setup">Setup the tool for the caller</param>
465 /// <returns>The Tool or an error if it this or previous setup attempts have failed</returns>
466 public static ValueOrError<Tool> ElseTrySetup(this ValueOrError<Tool> result, bool condition, string tool, Action setup)
467 => result.Else(condition, () =>
468 {
469 setup();
471 return ToolResolver.GetPathTool(tool);
472 });
473
474 /// <summary>
475 /// Try a different setup method for a Tool which may failed its installation
476 /// </summary>
477 /// <param name="result">Result of the previous attempt</param>
478 /// <param name="tool">The name of the tool</param>
479 /// <param name="setup">Setup the tool for the caller</param>
480 /// <returns>The Tool or an error if it this or previous setup attempts have failed</returns>
481 public static ValueOrError<Tool> ElseTrySetup(this ValueOrError<Tool> result, string tool, Action setup)
482 => result.ElseTrySetup(true, tool, setup);
483}
static Attempt Else(this Attempt self, Action action, Action< Exception >? onFailure=null)
If input attempt is an error then attempt to execute another input action (which may also fail)
static Tool WithEnvVars(this Tool tool, params(string key, object value)[] items)
A more comfortable passing of environment variables. This will also pass on parent environment.
static ToolEx WithSemanticLogging(this ToolEx tool, Func< string, bool >? filter=null, Action< OutputType, string >? normalOutputLogger=null)
Mark app output Debug/Info/Warning/Error based on its content rather than the stream they were added ...
static ToolArguments SemanticLogging(Func< string, bool >? filter=null, Action< OutputType, string >? normalOutputLogger=null)
Mark app output Debug/Info/Warning/Error based on its content rather than the stream they were added ...
static void UpdatePathEnvVar()
Attempt to update PATH of this process from user's environment variables.
Definition ToolCola.cs:433
static ToolEx WithEnvVar(this ToolEx tool, string key, object value, bool includeParentEnvironment=true)
A more comfortable passing of environment variables. This will also pass on parent environment.
static IEnumerable< Output > RemoveAnsiEscape(this IEnumerable< Output > toolOutput)
Removes ANSI escape sequences from the output of a Tool (remove color data for example)
static ToolArguments EnvVar(string key, object value, bool includeParentEnvironment=true)
A more comfortable passing of environment variables. This will also pass on parent environment.
Definition ToolCola.cs:285
static ToolEx With(this ToolEx tool, ToolArguments args)
Set individual Tool launching parameters and propagate the delegate further.
static ToolEx With(this ToolEx tool, ToolExArguments args)
Set individual Tool launching parameters and propagate the delegate further.
static ToolEx With(this ToolEx tool, ArgumentStringHandlerEx arguments=default, string? workingDirectory=null, IReadOnlyDictionary< string, string >? environmentVariables=null, int? timeout=null, bool? logOutput=null, bool? logInvocation=null, Action< OutputType, string >? logger=null, Action< IProcess >? exitHandler=null, Action< StreamWriter >? input=null, Encoding? standardOutputEncoding=null, Encoding? standardInputEncoding=null)
Set individual Tool launching parameters and propagate the delegate further.
static ValueOrError< Tool > ElseTrySetup(this ValueOrError< Tool > result, bool condition, string tool, Action setup)
Try a different setup method for a Tool which may failed its installation.
static ToolEx WithInput(this ToolEx tool, IEnumerable< string > lines)
Provide lines for standard input once the program is run. If the target program waits until end-of-st...
static ? IReadOnlyCollection< Output > ExecuteWith(this ToolEx tool, ToolExArguments args)
Execute a tool with standard input with the arguments provided by the input record.
static ToolEx WithPathVar(this ToolEx tool, AbsolutePath path)
Add an input path to this tool's PATH list. It won't be added if input path is already in there.
static Tool WithEnvVars(this Tool tool, bool includeParentEnvironment, params(string key, object value)[] items)
A more comfortable passing of environment variables. This will also pass on parent environment.
static IReadOnlyCollection< Output > ExecuteWith(this Tool tool, ToolArguments args)
Execute a tool with the arguments provided by the input record.
static ToolArguments CurrentEnvironment
ToolArguments for priming environment variables.
Definition ToolCola.cs:280
static ToolEx WithEnvVars(this ToolEx tool, bool includeParentEnvironment, params(string key, object value)[] items)
A more comfortable passing of environment variables. This will also pass on parent environment.
static ToolArguments EnvVars(bool includeParentEnvironment, params(string key, object value)[] items)
A more comfortable passing of environment variables. This will also pass on parent environment.
Definition ToolCola.cs:298
static ToolEx WithInput(this ToolEx tool, string line)
Provide a single line for standard input once the program is run.
static ValueOrError< Tool > Use(string tool, Action? setup=null)
Get a tool which should be in PATH, and provide an optional way to set it up automatically if it wasn...
static Tool WithEnvVar(this Tool tool, string key, object value, bool includeParentEnvironment=true)
A more comfortable passing of environment variables. This will also pass on parent environment.
static ToolEx WithEnvVars(this ToolEx tool, params(string key, object value)[] items)
A more comfortable passing of environment variables. This will also pass on parent environment.
static Tool With(this Tool tool, ToolArguments args)
Set individual Tool launching parameters and propagate the delegate further.
static Tool With(this Tool tool, ArgumentStringHandlerEx arguments=default, string? workingDirectory=null, IReadOnlyDictionary< string, string >? environmentVariables=null, int? timeout=null, bool? logOutput=null, bool? logInvocation=null, Action< OutputType, string >? logger=null, Action< IProcess >? exitHandler=null)
Set individual Tool launching parameters and propagate the delegate further.
static ToolArguments EnvVars(params(string key, object value)[] items)
A more comfortable passing of environment variables. This will also pass on parent environment.
static void StdErrorIsNotError(OutputType type, string output)
A tool output logger which doesn't treat standard error as error logs. Many tools for example send pr...
static ToolEx Pipe(this IEnumerable< Output > previous, ToolEx next, bool pipeError=false, bool close=true)
Pipe the results of a tool into the standard input of the next tool. This is not exactly the same as ...
static Tool WithPathVar(this Tool tool, AbsolutePath path)
Add an input path to this tool's PATH list. It won't be added if input path is already in there.
static Tool WithSemanticLogging(this Tool tool, Func< string, bool >? filter=null, Action< OutputType, string >? normalOutputLogger=null)
Mark app output Debug/Info/Warning/Error based on its content rather than the stream they were added ...
static ToolEx CloseInput(this ToolEx tool)
Explicitly close the standard input after other inputs have been queued. Some programs may freeze wit...
static ValueOrError< Tool > ElseTrySetup(this ValueOrError< Tool > result, string tool, Action setup)
Try a different setup method for a Tool which may failed its installation.
record class PropagateToolExExecution(ToolEx Target, ToolExArguments? PropagateArguments=null)
Propagated ToolEx delegate provider for launch parameter composition.
Definition ToolEx.cs:124
record class ToolArguments(string? Arguments=null, string? WorkingDirectory=null, IReadOnlyDictionary< string, string >? EnvironmentVariables=null, int? Timeout=null, bool? LogOutput=null, bool? LogInvocation=null, Action< OutputType, string >? Logger=null, Action< IProcess >? ExitHandler=null)
A record listing Tool delegate parameters and provides a way to meaningfully merge multiple together.
delegate? IReadOnlyCollection< Output > ToolEx(ArgumentStringHandlerEx arguments=default, string? workingDirectory=null, IReadOnlyDictionary< string, string >? environmentVariables=null, int? timeout=null, bool? logOutput=null, bool? logInvocation=null, Action< OutputType, string >? logger=null, Action< IProcess >? exitHandler=null, Action< StreamWriter >? input=null, Encoding? standardOutputEncoding=null, Encoding? standardInputEncoding=null)
Extended copy of Tool delegate of Nuke.
record class ToolExArguments(ToolArguments ToolArgs, Action< StreamWriter >? Input=null, Encoding? StandardOutputEncoding=null, Encoding? StandardInputEncoding=null)
A record listing Tool and ToolEx delegate parameters and provides a way to meaningfully merge multipl...
Definition ToolEx.cs:39
record class PropagateToolExecution(Tool Target, ToolArguments? PropagateArguments=null)
Propagated Tool delegate provider for launch parameter composition.