Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions Sources/containertool/containertool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,28 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
@Option(help: "Resource bundle directory")
private var resources: [String] = []

@Option(help: "Default username, used if there are no matching entries in .netrc")
@Option(
help: ArgumentHelp(
"[DEPRECATED] Default username, used if there are no matching entries in .netrc. Use --default-username instead.",
visibility: .private
)
)
private var username: String?

@Option(help: "Default password, used if there are no matching entries in .netrc")
@Option(help: "Default username, used if there are no matching entries in .netrc")
private var defaultUsername: String?

@Option(
help: ArgumentHelp(
"[DEPRECATED] Default password, used if there are no matching entries in .netrc. Use --default-password instead.",
visibility: .private
)
)
private var password: String?

@Option(help: "Default password, used if there are no matching entries in .netrc")
private var defaultPassword: String?

@Flag(name: .shortAndLong, help: "Verbose output")
private var verbose: Bool = false

Expand All @@ -70,13 +86,37 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
@Option(help: "Specify the netrc file path")
private var netrcFile: String?

mutating func validate() throws {
if username != nil {
guard defaultUsername == nil else {
throw ValidationError(
"--default-username and --username cannot be specified together. Please use --default-username only."
)
}

log("Deprecation warning: --username is deprecated, please use --default-username instead.")
defaultUsername = username
}

if password != nil {
guard defaultPassword == nil else {
throw ValidationError(
"--default-password and --password cannot be specified together. Please use --default-password only."
)
}

log("Deprecation warning: --password is deprecated, please use --default-password instead.")
defaultPassword = password
}
}

func run() async throws {
// MARK: Apply defaults for unspecified configuration flags

let env = ProcessInfo.processInfo.environment
let defaultRegistry = defaultRegistry ?? env["CONTAINERTOOL_DEFAULT_REGISTRY"] ?? "docker.io"
let username = username ?? env["CONTAINERTOOL_USERNAME"]
let password = password ?? env["CONTAINERTOOL_PASSWORD"]
let username = defaultUsername ?? env["CONTAINERTOOL_DEFAULT_USERNAME"]
let password = defaultPassword ?? env["CONTAINERTOOL_DEFAULT_PASSWORD"]
let from = from ?? env["CONTAINERTOOL_BASE_IMAGE"] ?? "swift:slim"
let os = os ?? env["CONTAINERTOOL_OS"] ?? "linux"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ Wrap a binary in a container image and publish it.

If the `product` being packaged has a [resource bundle](https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package) it will be added to the image automatically.

- term `--username <username>`:
- term `--default-username <username>`:
Default username to use when logging into the registry.

This username is used if there is no matching `.netrc` entry for the registry, there is no `.netrc` file, or the `--disable-netrc` option is set.
The same username is used for the source and destination registries.

- term `--password <password>`:
- term `--default-password <password>`:
Default password to use when logging into the registry.

This password is used if there is no matching `.netrc` entry for the registry, there is no `.netrc` file, or the `--disable-netrc` option is set.
Expand Down