-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerCustom.cs
More file actions
61 lines (56 loc) · 2.26 KB
/
Copy pathDockerCustom.cs
File metadata and controls
61 lines (56 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ReSharper disable UnusedMember.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedType.Global
namespace HostApi;
using Internal;
//github.com/ <summary>
//github.com/ The docker custom command is used to execute any docker commands with any arguments.
//github.com/ <example>
//github.com/ <code>
//github.com/ var hasLinuxDocker = false;
//github.com/ new DockerCustom("info").Run(output =>
//github.com/ {
//github.com/ if (output.Line.Contains("OSType: linux"))
//github.com/ {
//github.com/ hasLinuxDocker = true;
//github.com/ }
//github.com/ });
//github.com/ </code>
//github.com/ </example>
//github.com/ </summary>
//github.com/ <param name="Args">Specifies the set of command line arguments to use when starting the tool.</param>
//github.com/ <param name="Vars">Specifies the set of environment variables that apply to this process and its child processes.</param>
//github.com/ <param name="ExecutablePath">Overrides the tool executable path.</param>
//github.com/ <param name="WorkingDirectory">Specifies the working directory for the tool to be started.</param>
//github.com/ <param name="ShortName"> Specifies a short name for this operation.</param>
[Target]
public partial record DockerCustom(
IEnumerable<string> Args,
IEnumerable<(string name, string value)> Vars,
string ExecutablePath = "",
string WorkingDirectory = "",
string ShortName = "")
{
//github.com/ <summary>
//github.com/ Create a new instance of the command.
//github.com/ </summary>
//github.com/ <param name="args">Specifies the set of command line arguments to use when starting the tool.</param>
public DockerCustom(params string[] args)
: this(args, [])
{ }
//github.com/ <inheritdoc/>
public IStartInfo GetStartInfo(IHost host)
{
if (host == null) throw new ArgumentNullException(nameof(host));
return new CommandLine(string.IsNullOrWhiteSpace(ExecutablePath) ? host.GetService<HostComponents>().DockerSettings.DockerExecutablePath : ExecutablePath)
.WithShortName(ToString())
.WithWorkingDirectory(WorkingDirectory)
.WithVars(Vars.ToArray())
.WithArgs(Args.ToArray());
}
//github.com/ <inheritdoc/>
public override string ToString() =>
string.IsNullOrWhiteSpace(ShortName)
? ((ExecutablePath == string.Empty ? "docker" : Path.GetFileNameWithoutExtension(ExecutablePath)) + " " + Args.FirstOrDefault()).TrimEnd()
: ShortName;
}