Skip to content

Commit 022b215

Browse files
authored
Add token-file option to 'package-registry login' (#6567)
* Add token-file option to 'package-registry login' rdar://109372471 * No need to do .cString
1 parent 3e34d05 commit 022b215

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Sources/PackageRegistryTool/PackageRegistryTool+Auth.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ extension SwiftPackageRegistryTool {
8383
@Option(help: "Access token")
8484
var token: String?
8585

86+
@Option(
87+
name: .customLong("token-file"),
88+
help: "Path to the file containing access token"
89+
)
90+
var tokenFilePath: AbsolutePath?
91+
8692
@Flag(help: "Allow writing to netrc file without confirmation")
8793
var noConfirm: Bool = false
8894

@@ -145,6 +151,10 @@ extension SwiftPackageRegistryTool {
145151
if let token {
146152
// User provided token
147153
storePassword = token
154+
} else if let tokenFilePath {
155+
print("Reading access token from \(tokenFilePath).")
156+
storePassword = try localFileSystem.readFileContents(tokenFilePath)
157+
.trimmingCharacters(in: .whitespacesAndNewlines)
148158
} else if let stored = authorizationProvider.authentication(for: registryURL),
149159
stored.user == storeUsername
150160
{

0 commit comments

Comments
 (0)