forked from apple/container
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlags.swift
More file actions
153 lines (114 loc) · 6.1 KB
/
Flags.swift
File metadata and controls
153 lines (114 loc) · 6.1 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//===----------------------------------------------------------------------===//
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
import ArgumentParser
import Foundation
public struct Flags {
public struct Global: ParsableArguments {
public init() {}
@Flag(name: .long, help: "Enable debug output [environment: CONTAINER_DEBUG]")
public var debug = false
}
public struct Process: ParsableArguments {
public init() {}
@Option(
name: [.customLong("cwd"), .customShort("w"), .customLong("workdir")],
help: "Current working directory for the container")
public var cwd: String?
@Option(name: [.customLong("env"), .customShort("e")], help: "Set environment variables")
public var env: [String] = []
@Option(name: .customLong("env-file"), help: "Read in a file of environment variables")
public var envFile: [String] = []
@Option(name: .customLong("uid"), help: "Set the uid for the process")
public var uid: UInt32?
@Option(name: .customLong("gid"), help: "Set the gid for the process")
public var gid: UInt32?
@Flag(name: [.customLong("interactive"), .customShort("i")], help: "Keep Stdin open even if not attached")
public var interactive = false
@Flag(name: [.customLong("tty"), .customShort("t")], help: "Open a tty with the process")
public var tty = false
@Option(name: [.customLong("user"), .customShort("u")], help: "Set the user for the process")
public var user: String?
}
public struct Resource: ParsableArguments {
public init() {}
@Option(name: [.customLong("cpus"), .customShort("c")], help: "Number of CPUs to allocate to the container")
public var cpus: Int64?
@Option(
name: [.customLong("memory"), .customShort("m")],
help:
"Amount of memory in bytes, kilobytes (K), megabytes (M), or gigabytes (G) for the container, with MB granularity (for example, 1024K will result in 1MB being allocated for the container)"
)
public var memory: String?
}
public struct Registry: ParsableArguments {
public init() {}
public init(scheme: String) {
self.scheme = scheme
}
@Option(help: "Scheme to use when conntecting to the container registry. One of (http, https, auto)")
public var scheme: String = "auto"
}
public struct Management: ParsableArguments {
public init() {}
@Flag(name: [.customLong("detach"), .customShort("d")], help: "Run the container and detach from the process")
public var detach = false
@Option(name: .customLong("entrypoint"), help: "Override the entrypoint of the image")
public var entryPoint: String?
@Option(name: .customLong("mount"), help: "Add a mount to the container (type=<>,source=<>,target=<>,readonly)")
public var mounts: [String] = []
@Option(name: .customLong("tmpfs"), help: "Add a tmpfs mount to the container at the given path")
public var tmpFs: [String] = []
@Option(name: .customLong("name"), help: "Assign a name to the container. If excluded will be a generated UUID")
public var name: String?
@Flag(name: [.customLong("remove"), .customLong("rm")], help: "Remove the container after it stops")
public var remove = false
@Option(name: .customLong("os"), help: "Set OS if image can target multiple operating systems")
public var os = "linux"
@Option(
name: [.customLong("arch"), .customShort("a")], help: "Set arch if image can target multiple architectures")
public var arch: String = Arch.hostArchitecture().rawValue
@Option(name: [.customLong("volume"), .customShort("v")], help: "Bind mount a volume into the container")
public var volumes: [String] = []
@Option(
name: [.customLong("kernel"), .customShort("k")], help: "Set a custom kernel path", completion: .file(),
transform: { str in
URL(fileURLWithPath: str, relativeTo: .currentDirectory()).absoluteURL.path(percentEncoded: false)
})
public var kernel: String?
@Option(name: .customLong("cidfile"), help: "Write the container ID to the path provided")
public var cidfile = ""
@Flag(name: [.customLong("no-dns")], help: "Do not configure DNS in the container")
public var dnsDisabled = false
@Option(name: .customLong("dns"), help: "DNS nameserver IP address")
public var dnsNameservers: [String] = []
@Option(name: .customLong("dns-domain"), help: "Default DNS domain")
public var dnsDomain: String? = nil
@Option(name: .customLong("dns-search"), help: "DNS search domains")
public var dnsSearchDomains: [String] = []
@Option(name: .customLong("dns-option"), help: "DNS options")
public var dnsOptions: [String] = []
@Option(name: [.customLong("label"), .customShort("l")], help: "Add a key=value label to the container")
public var labels: [String] = []
}
public struct Progress: ParsableArguments {
public init() {}
public init(disableProgressUpdates: Bool) {
self.disableProgressUpdates = disableProgressUpdates
}
@Flag(name: .customLong("disable-progress-updates"), help: "Disable progress bar updates")
public var disableProgressUpdates = false
}
}