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