Skip to content

Commit 49f92be

Browse files
authored
containertool: Rename --username/password to --default-username/password (#125)
Motivation ---------- The `--username` and `--password` options define default values which are used if no suitable credentials can be found in `.netrc`. Their current names could imply that they override other sources of credentials - the help originally said this was the case (#123). Renaming them to `--default-username` and `--default-password` reduces the risk of misunderstanding. Modifications ------------- * Rename the `--user` and `--password` options to `--default-user` and `--default-password`. * Add checks to warn that the old versions are deprecated, and fail if both are provided together. * Hide the old options from `--help` and remove them from the manual page * Rename the environment variable versions of these options. The environment variable change had not yet been released so deprecation warnings are not needed. Result ------ * New users will see more descriptive option names * Existing users will be prompted to change the options they pass Test Plan --------- All existing test continue to pass.
1 parent 2a4523b commit 49f92be

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

Sources/containertool/containertool.swift

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,28 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
4040
@Option(help: "Resource bundle directory")
4141
private var resources: [String] = []
4242

43-
@Option(help: "Default username, used if there are no matching entries in .netrc")
43+
@Option(
44+
help: ArgumentHelp(
45+
"[DEPRECATED] Default username, used if there are no matching entries in .netrc. Use --default-username instead.",
46+
visibility: .private
47+
)
48+
)
4449
private var username: String?
4550

46-
@Option(help: "Default password, used if there are no matching entries in .netrc")
51+
@Option(help: "Default username, used if there are no matching entries in .netrc")
52+
private var defaultUsername: String?
53+
54+
@Option(
55+
help: ArgumentHelp(
56+
"[DEPRECATED] Default password, used if there are no matching entries in .netrc. Use --default-password instead.",
57+
visibility: .private
58+
)
59+
)
4760
private var password: String?
4861

62+
@Option(help: "Default password, used if there are no matching entries in .netrc")
63+
private var defaultPassword: String?
64+
4965
@Flag(name: .shortAndLong, help: "Verbose output")
5066
private var verbose: Bool = false
5167

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

89+
mutating func validate() throws {
90+
if username != nil {
91+
guard defaultUsername == nil else {
92+
throw ValidationError(
93+
"--default-username and --username cannot be specified together. Please use --default-username only."
94+
)
95+
}
96+
97+
log("Deprecation warning: --username is deprecated, please use --default-username instead.")
98+
defaultUsername = username
99+
}
100+
101+
if password != nil {
102+
guard defaultPassword == nil else {
103+
throw ValidationError(
104+
"--default-password and --password cannot be specified together. Please use --default-password only."
105+
)
106+
}
107+
108+
log("Deprecation warning: --password is deprecated, please use --default-password instead.")
109+
defaultPassword = password
110+
}
111+
}
112+
73113
func run() async throws {
74114
// MARK: Apply defaults for unspecified configuration flags
75115

76116
let env = ProcessInfo.processInfo.environment
77117
let defaultRegistry = defaultRegistry ?? env["CONTAINERTOOL_DEFAULT_REGISTRY"] ?? "docker.io"
78-
let username = username ?? env["CONTAINERTOOL_USERNAME"]
79-
let password = password ?? env["CONTAINERTOOL_PASSWORD"]
118+
let username = defaultUsername ?? env["CONTAINERTOOL_DEFAULT_USERNAME"]
119+
let password = defaultPassword ?? env["CONTAINERTOOL_DEFAULT_PASSWORD"]
80120
let from = from ?? env["CONTAINERTOOL_BASE_IMAGE"] ?? "swift:slim"
81121
let os = os ?? env["CONTAINERTOOL_OS"] ?? "linux"
82122

Sources/swift-container-plugin/Documentation.docc/build-container-image.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ Wrap a binary in a container image and publish it.
3333

3434
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.
3535

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

3939
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.
4040
The same username is used for the source and destination registries.
4141

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

4545
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.

0 commit comments

Comments
 (0)