Skip to content

Commit 1d2703d

Browse files
committed
containertool: Allow destination repository to be set by an environment variable
1 parent 49f92be commit 1d2703d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Sources/containertool/containertool.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
3232
private var defaultRegistry: String?
3333

3434
@Option(help: "Repository path")
35-
private var repository: String
35+
private var repository: String?
3636

3737
@Argument(help: "Executable to package")
3838
private var executable: String
@@ -114,7 +114,14 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
114114
// MARK: Apply defaults for unspecified configuration flags
115115

116116
let env = ProcessInfo.processInfo.environment
117+
117118
let defaultRegistry = defaultRegistry ?? env["CONTAINERTOOL_DEFAULT_REGISTRY"] ?? "docker.io"
119+
guard let repository = repository ?? env["CONTAINERTOOL_REPOSITORY"] else {
120+
throw ValidationError(
121+
"Please specify the destination repository using --repository or CONTAINERTOOL_REPOSITORY"
122+
)
123+
}
124+
118125
let username = defaultUsername ?? env["CONTAINERTOOL_DEFAULT_USERNAME"]
119126
let password = defaultPassword ?? env["CONTAINERTOOL_DEFAULT_PASSWORD"]
120127
let from = from ?? env["CONTAINERTOOL_BASE_IMAGE"] ?? "swift:slim"

scripts/test-plugin-output-streaming.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ swift package --package-path "$PKGPATH" --allow-network-connections all build-co
4646
set -o pipefail
4747

4848
# This checks that the output lines are not broken, but not that they appear in the correct order
49-
grep -F -x -e "error: Missing expected argument '--repository <repository>'" \
50-
-e "error: Help: --repository <repository> Repository path" \
51-
-e "error: Usage: containertool [<options>] --repository <repository> <executable>" \
49+
grep -F -x -e "error: Please specify the destination repository using --repository or CONTAINERTOOL_REPOSITORY" \
50+
-e "error: Usage: containertool [<options>] <executable>" \
5251
-e "error: See 'containertool --help' for more information." "$PKGPATH/output"
5352

5453
log Plugin error output: PASSED

0 commit comments

Comments
 (0)