From 516b438bf4488d399d384daa0f0a01fa5ca8204a Mon Sep 17 00:00:00 2001 From: Sam Deane Date: Tue, 10 Sep 2024 16:14:00 +0100 Subject: [PATCH] Fixed uploading. --- .vscode/launch.json | 12 +++ Sources/ReleaseTools/OptionParser.swift | 101 +++++++++++++----------- 2 files changed, 68 insertions(+), 45 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 751ea00..439fb37 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -43,5 +43,17 @@ "program": "${workspaceFolder:ReleaseTools}/.build/debug/rt", "preLaunchTask": "swift: Build Debug rt" }, + { + "type": "swift-lldb", + "request": "launch", + "args": [ + "upload", + "--platform=macOS", + ], + "cwd": "${workspaceFolder:ReleaseTools}/../Stack", + "name": "Debug -- upload Stack", + "program": "${workspaceFolder:ReleaseTools}/.build/debug/rt", + "preLaunchTask": "swift: Build Debug rt" + }, ] } \ No newline at end of file diff --git a/Sources/ReleaseTools/OptionParser.swift b/Sources/ReleaseTools/OptionParser.swift index ee1d4ec..e986f00 100644 --- a/Sources/ReleaseTools/OptionParser.swift +++ b/Sources/ReleaseTools/OptionParser.swift @@ -19,61 +19,61 @@ enum GeneralError: Error, CustomStringConvertible, Sendable { public var description: String { switch self { - case .infoUnreadable(let path): return "Couldn't read archive info.plist.\n\(path)" + case .infoUnreadable(let path): return "Couldn't read archive info.plist.\n\(path)" - case .missingWorkspace: return "The workspace was not specified, and could not be inferred." + case .missingWorkspace: return "The workspace was not specified, and could not be inferred." - case .taggingFailed: return "Tagging failed." + case .taggingFailed: return "Tagging failed." - case .noDefaultUser: - return """ - No user specified. - Either supply a value with --user , or set a default value using: + case .noDefaultUser: + return """ + No user specified. + Either supply a value with --user , or set a default value using: - \(CommandLine.name) set user . + \(CommandLine.name) set user . - A corresponding app-specific password should be stored in your keychain. - See https://support.apple.com/en-us/HT204397 for more details. - """ + A corresponding app-specific password should be stored in your keychain. + See https://support.apple.com/en-us/HT204397 for more details. + """ - case .apiKeyAndIssuer: - return """ - You need to supply both --api-key and --api-issuer together. - Either supply both values on the command line, or set default values using: + case .apiKeyAndIssuer: + return """ + You need to supply both --api-key and --api-issuer together. + Either supply both values on the command line, or set default values using: - \(CommandLine.name) set api-key - \(CommandLine.name) set api-issuer + \(CommandLine.name) set api-key + \(CommandLine.name) set api-issuer - A corresponding .p8 key file should be stored in ~/.appstoreconnect/private_keys/ - See https://appstoreconnect.apple.com/access/api to generate a key. - """ + A corresponding .p8 key file should be stored in ~/.appstoreconnect/private_keys/ + See https://appstoreconnect.apple.com/access/api to generate a key. + """ - case .userOrApiKey: - return """ - You need to supply either --user, or --api-key and --api-issuer together. - If you are using --user, either supply it on the command line, or set a - default value using: + case .userOrApiKey: + return """ + You need to supply either --user, or --api-key and --api-issuer together. + If you are using --user, either supply it on the command line, or set a + default value using: - \(CommandLine.name) set user + \(CommandLine.name) set user - A corresponding app-specific password should be stored in your keychain. - See https://support.apple.com/en-us/HT204397 for more details. + A corresponding app-specific password should be stored in your keychain. + See https://support.apple.com/en-us/HT204397 for more details. - If you are using an api key, either supply both --api-key and --api-issuer - on the command line, or set default values using: + If you are using an api key, either supply both --api-key and --api-issuer + on the command line, or set default values using: - \(CommandLine.name) set api-key - \(CommandLine.name) set api-issuer + \(CommandLine.name) set api-key + \(CommandLine.name) set api-issuer - A corresponding .p8 key file should be stored in ~/.appstoreconnect/private_keys/ - See https://appstoreconnect.apple.com/access/api to generate a key. - """ + A corresponding .p8 key file should be stored in ~/.appstoreconnect/private_keys/ + See https://appstoreconnect.apple.com/access/api to generate a key. + """ - case .noDefaultScheme(let platform): - return """ - No scheme specified for \(platform). - Either supply a value with --scheme , or set a default value using \(CommandLine.name) set scheme --platform \(platform)." - """ + case .noDefaultScheme(let platform): + return """ + No scheme specified for \(platform). + Either supply a value with --scheme , or set a default value using \(CommandLine.name) set scheme --platform \(platform)." + """ } } } @@ -163,7 +163,7 @@ class OptionParser { } if scheme != nil { - if let scheme = scheme?.scheme ?? getDefault(for: "scheme") { + if let scheme = scheme?.scheme ?? defaultScheme { self.scheme = scheme } else { throw GeneralError.noDefaultScheme(self.platform) @@ -219,17 +219,28 @@ class OptionParser { } } + /// Read a default value from the settings. + /// We look for a platform-specific value first, and fall back on a general value if that doesn't exist. func getDefault(for key: String) -> String? { // try platform specific key first, if the platform has been specified if !platform.isEmpty, - let value = UserDefaults.standard.string(forKey: defaultKey(for: key, platform: platform)) + let platformValue = UserDefaults.standard.string(forKey: defaultKey(for: key, platform: platform)) { - return value + return platformValue } // fall back on general key - if let scheme = UserDefaults.standard.string(forKey: defaultKey(for: key, platform: "")) { - return scheme + if let generalValue = UserDefaults.standard.string(forKey: defaultKey(for: key, platform: "")) { + return generalValue + } + + return nil + } + + /// If no scheme is supplied, we'll try to guess one based on the workspace. + var defaultScheme: String? { + if let value = getDefault(for: "scheme") { + return value } if let ws = defaultWorkspace {