Skip to content

Commit c791052

Browse files
authored
Add init methods for all the members of the Flags type (#1203)
## Type of Change - [ ] Bug fix - [x] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context Authors of CLI plugins for container will be able to reuse the container flags defined in the CLI package, instead of having to duplicate them in their project ## Testing - [ ] Tested locally - [ ] Added/updated tests - [ ] Added/updated docs
1 parent dfac83d commit c791052

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

Sources/Services/ContainerAPIService/Client/Flags.swift

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,39 @@ public struct Flags {
2222
public struct Logging: ParsableArguments {
2323
public init() {}
2424

25+
public init(debug: Bool) {
26+
self.debug = debug
27+
}
28+
2529
@Flag(name: .long, help: "Enable debug output [environment: CONTAINER_DEBUG]")
2630
public var debug = false
2731
}
2832

2933
public struct Process: ParsableArguments {
3034
public init() {}
3135

36+
public init(
37+
cwd: String?,
38+
env: [String],
39+
envFile: [String],
40+
gid: UInt32?,
41+
interactive: Bool,
42+
tty: Bool,
43+
uid: UInt32?,
44+
ulimits: [String],
45+
user: String?
46+
) {
47+
self.cwd = cwd
48+
self.env = env
49+
self.envFile = envFile
50+
self.gid = gid
51+
self.interactive = interactive
52+
self.tty = tty
53+
self.uid = uid
54+
self.ulimits = ulimits
55+
self.user = user
56+
}
57+
3258
@Option(name: .shortAndLong, help: "Set environment variables (key=value, or just key to inherit from host)")
3359
public var env: [String] = []
3460

@@ -75,6 +101,11 @@ public struct Flags {
75101
public struct Resource: ParsableArguments {
76102
public init() {}
77103

104+
public init(cpus: Int64?, memory: String?) {
105+
self.cpus = cpus
106+
self.memory = memory
107+
}
108+
78109
@Option(name: .shortAndLong, help: "Number of CPUs to allocate to the container")
79110
public var cpus: Int64?
80111

@@ -88,6 +119,13 @@ public struct Flags {
88119
public struct DNS: ParsableArguments {
89120
public init() {}
90121

122+
public init(domain: String?, nameservers: [String], options: [String], searchDomains: [String]) {
123+
self.domain = domain
124+
self.nameservers = nameservers
125+
self.options = options
126+
self.searchDomains = searchDomains
127+
}
128+
91129
@Option(
92130
name: .customLong("dns"),
93131
help: .init("DNS nameserver IP address", valueName: "ip")
@@ -127,6 +165,58 @@ public struct Flags {
127165
public struct Management: ParsableArguments {
128166
public init() {}
129167

168+
public init(
169+
arch: String,
170+
cidfile: String,
171+
detach: Bool,
172+
dns: Flags.DNS,
173+
dnsDisabled: Bool,
174+
entrypoint: String?,
175+
initImage: String?,
176+
kernel: String?,
177+
labels: [String],
178+
mounts: [String],
179+
name: String?,
180+
networks: [String],
181+
os: String,
182+
platform: String?,
183+
publishPorts: [String],
184+
publishSockets: [String],
185+
readOnly: Bool,
186+
remove: Bool,
187+
rosetta: Bool,
188+
runtime: String?,
189+
ssh: Bool,
190+
tmpFs: [String],
191+
virtualization: Bool,
192+
volumes: [String]
193+
) {
194+
self.arch = arch
195+
self.cidfile = cidfile
196+
self.detach = detach
197+
self.dns = dns
198+
self.dnsDisabled = dnsDisabled
199+
self.entrypoint = entrypoint
200+
self.initImage = initImage
201+
self.kernel = kernel
202+
self.labels = labels
203+
self.mounts = mounts
204+
self.name = name
205+
self.networks = networks
206+
self.os = os
207+
self.platform = platform
208+
self.publishPorts = publishPorts
209+
self.publishSockets = publishSockets
210+
self.readOnly = readOnly
211+
self.remove = remove
212+
self.rosetta = rosetta
213+
self.runtime = runtime
214+
self.ssh = ssh
215+
self.tmpFs = tmpFs
216+
self.virtualization = virtualization
217+
self.volumes = volumes
218+
}
219+
130220
@Option(name: .shortAndLong, help: "Set arch if image can target multiple architectures")
131221
public var arch: String = Arch.hostArchitecture().rawValue
132222

@@ -235,6 +325,10 @@ public struct Flags {
235325
public struct Progress: ParsableArguments {
236326
public init() {}
237327

328+
public init(progress: ProgressType) {
329+
self.progress = progress
330+
}
331+
238332
public enum ProgressType: String, ExpressibleByArgument {
239333
case none
240334
case ansi
@@ -247,6 +341,10 @@ public struct Flags {
247341
public struct ImageFetch: ParsableArguments {
248342
public init() {}
249343

344+
public init(maxConcurrentDownloads: Int) {
345+
self.maxConcurrentDownloads = maxConcurrentDownloads
346+
}
347+
250348
@Option(name: .long, help: "Maximum number of concurrent downloads (default: 3)")
251349
public var maxConcurrentDownloads: Int = 3
252350
}

0 commit comments

Comments
 (0)