From 59835fad4c9b8f4102b92e1bfc325b7ce399b8bd Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 16 Aug 2020 17:00:18 -0700 Subject: [PATCH 1/6] Adding --quiet flag --- .../Commands/Certificates/ListCertificatesCommand.swift | 4 +++- .../Commands/Certificates/ReadCertificateCommand.swift | 4 +++- .../Commands/Certificates/RevokeCertificatesCommand.swift | 6 ++++-- .../AppStoreConnectCLI/Commands/CommonParsableCommand.swift | 3 +++ .../Commands/Profiles/ListProfilesCommand.swift | 4 +++- .../Commands/Users/SyncUsersCommand.swift | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift index 03b917b4..f6888517 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift @@ -55,7 +55,9 @@ struct ListCertificatesCommand: CommonParsableCommand { let file = try certificateProcessor.write($0) - print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)") + if common.quiet == false { + print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)") + } } } diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift index bdf200dc..400a3a84 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift @@ -28,7 +28,9 @@ struct ReadCertificateCommand: CommonParsableCommand { let file = try fileProcessor.write(certificate) - print("📥 Certificate '\(certificate.name ?? "")' downloaded to: \(file.path)") + if common.quiet == false { + print("📥 Certificate '\(certificate.name ?? "")' downloaded to: \(file.path)") + } } certificate.render(format: common.outputFormat) diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift index 8182a4cc..5ca5a74b 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift @@ -25,8 +25,10 @@ struct RevokeCertificatesCommand: CommonParsableCommand { let service = try makeService() _ = try service.revokeCertificates(serials: serials) - serials.forEach { - print("🚮 Certificate `\($0)` revoked.") + if common.quiet == false { + serials.forEach { + print("🚮 Certificate `\($0)` revoked.") + } } } diff --git a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift index fdba9533..f705960f 100755 --- a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift @@ -22,4 +22,7 @@ struct CommonOptions: ParsableArguments { @Flag(default: .table, help: "Display results in specified format.") var outputFormat: OutputFormat + + @Flag(name: .shortAndLong, help: "Show less messages in stdout") + var quiet: Bool } diff --git a/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift index a8a18ece..c75110fb 100644 --- a/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift @@ -79,7 +79,9 @@ struct ListProfilesCommand: CommonParsableCommand { try profiles.forEach { let file = try processor.write($0) - print("📥 Profile '\($0.name!)' downloaded to: \(file.path)") + if common.quiet == false { + print("📥 Profile '\($0.name!)' downloaded to: \(file.path)") + } } } diff --git a/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift b/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift index b8e92596..f82e087f 100755 --- a/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift @@ -31,7 +31,7 @@ struct SyncUsersCommand: CommonParsableCommand { var dryRun: Bool func run() throws { - if dryRun { + if dryRun, common.quiet == false { print("## Dry run ##") } From e3739f0703b647250cd89d23d072a9b1e1b08bf3 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 16 Aug 2020 23:07:17 -0700 Subject: [PATCH 2/6] Better help information --- Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift index f705960f..b545fac7 100755 --- a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift @@ -23,6 +23,6 @@ struct CommonOptions: ParsableArguments { @Flag(default: .table, help: "Display results in specified format.") var outputFormat: OutputFormat - @Flag(name: .shortAndLong, help: "Show less messages in stdout") + @Flag(name: .shortAndLong, help: "Display less messaging in standard output.") var quiet: Bool } From f3b5c8718b791686cd2598ae895ad5436d0a947f Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 22 Aug 2020 23:28:36 -0700 Subject: [PATCH 3/6] Refactored quiet into verbose --- .../Commands/Certificates/ListCertificatesCommand.swift | 3 ++- .../Commands/Certificates/ReadCertificateCommand.swift | 3 ++- .../Commands/Certificates/RevokeCertificatesCommand.swift | 3 ++- .../AppStoreConnectCLI/Commands/CommonParsableCommand.swift | 5 +++-- .../Commands/Profiles/ListProfilesCommand.swift | 3 ++- .../AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift | 3 ++- .../AppStoreConnectCLI/Readers and Renderers/Renderers.swift | 4 +++- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift index f6888517..0a02bc35 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift @@ -55,7 +55,8 @@ struct ListCertificatesCommand: CommonParsableCommand { let file = try certificateProcessor.write($0) - if common.quiet == false { + // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` + if common.verbose || common.outputFormat == .table { print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)") } } diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift index 400a3a84..33916bdc 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift @@ -28,7 +28,8 @@ struct ReadCertificateCommand: CommonParsableCommand { let file = try fileProcessor.write(certificate) - if common.quiet == false { + // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` + if common.verbose || common.outputFormat == .table { print("📥 Certificate '\(certificate.name ?? "")' downloaded to: \(file.path)") } } diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift index 5ca5a74b..9dea43c9 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift @@ -25,7 +25,8 @@ struct RevokeCertificatesCommand: CommonParsableCommand { let service = try makeService() _ = try service.revokeCertificates(serials: serials) - if common.quiet == false { + // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` + if common.verbose || common.outputFormat == .table { serials.forEach { print("🚮 Certificate `\($0)` revoked.") } diff --git a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift index b545fac7..2494862e 100755 --- a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift @@ -23,6 +23,7 @@ struct CommonOptions: ParsableArguments { @Flag(default: .table, help: "Display results in specified format.") var outputFormat: OutputFormat - @Flag(name: .shortAndLong, help: "Display less messaging in standard output.") - var quiet: Bool + /// Used to print status messages. Defaults to `false`, except for `--table`, so all commands are parsable by default. + @Flag(name: .shortAndLong, help: "Display extra messages as command is running.") + var verbose: Bool } diff --git a/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift index c75110fb..7f0e335d 100644 --- a/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift @@ -79,7 +79,8 @@ struct ListProfilesCommand: CommonParsableCommand { try profiles.forEach { let file = try processor.write($0) - if common.quiet == false { + // Command output is parsable by default. Only print if verbosity is enabled or output is a `.table` + if common.verbose || common.outputFormat == .table { print("📥 Profile '\($0.name!)' downloaded to: \(file.path)") } } diff --git a/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift b/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift index f82e087f..aff660e6 100755 --- a/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift @@ -31,7 +31,8 @@ struct SyncUsersCommand: CommonParsableCommand { var dryRun: Bool func run() throws { - if dryRun, common.quiet == false { + // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` + if dryRun, common.verbose || common.outputFormat == .table { print("## Dry run ##") } diff --git a/Sources/AppStoreConnectCLI/Readers and Renderers/Renderers.swift b/Sources/AppStoreConnectCLI/Readers and Renderers/Renderers.swift index bf37fcdf..b575ece6 100644 --- a/Sources/AppStoreConnectCLI/Readers and Renderers/Renderers.swift +++ b/Sources/AppStoreConnectCLI/Readers and Renderers/Renderers.swift @@ -55,7 +55,9 @@ protocol ResultRenderable: Codable { extension ResultRenderable { func renderAsJSON() -> String { let jsonEncoder = JSONEncoder() - jsonEncoder.outputFormatting = [.prettyPrinted, .sortedKeys] + // Withholding `.prettyPrinted` to maintain output that is parsable by default. + // Consider adding the option `--pretty` if needed https://github.com/ittybittyapps/appstoreconnect-cli/issues/221 + jsonEncoder.outputFormatting = [.sortedKeys] let json = try! jsonEncoder.encode(self) // swiftlint:disable:this force_try return String(data: json, encoding: .utf8)! } From d6b5beaee43d94a8d6a9471e500267f06c4c625c Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 25 Aug 2020 21:51:38 -0700 Subject: [PATCH 4/6] Created PrintLevel, cleaned up duplicative logic --- .../ListCertificatesCommand.swift | 4 ++-- .../Certificates/ReadCertificateCommand.swift | 4 ++-- .../RevokeCertificatesCommand.swift | 4 ++-- .../Commands/CommonParsableCommand.swift | 23 ++++++++++++++++++- .../Commands/Users/SyncUsersCommand.swift | 4 ++-- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift index 0a02bc35..5351dcba 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift @@ -55,8 +55,8 @@ struct ListCertificatesCommand: CommonParsableCommand { let file = try certificateProcessor.write($0) - // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` - if common.verbose || common.outputFormat == .table { + // Only print if the `PrintLevel` is set to verbose. + if common.printLevel == .verbose { print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)") } } diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift index 33916bdc..d7fcfbf6 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift @@ -28,8 +28,8 @@ struct ReadCertificateCommand: CommonParsableCommand { let file = try fileProcessor.write(certificate) - // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` - if common.verbose || common.outputFormat == .table { + // Only print if the `PrintLevel` is set to verbose. + if common.printLevel == .verbose { print("📥 Certificate '\(certificate.name ?? "")' downloaded to: \(file.path)") } } diff --git a/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift index 9dea43c9..1725f884 100644 --- a/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift @@ -25,8 +25,8 @@ struct RevokeCertificatesCommand: CommonParsableCommand { let service = try makeService() _ = try service.revokeCertificates(serials: serials) - // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` - if common.verbose || common.outputFormat == .table { + // Only print if the `PrintLevel` is set to verbose. + if common.printLevel == .verbose { serials.forEach { print("🚮 Certificate `\($0)` revoked.") } diff --git a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift index 2494862e..9462136a 100755 --- a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift @@ -10,6 +10,14 @@ protocol CommonParsableCommand: ParsableCommand { func makeService() throws -> AppStoreConnectService } +/// A level representing the verbosity of command. +enum PrintLevel { + // Withholds displaying normal status messages + case quiet + // Displays all status messages + case verbose +} + extension CommonParsableCommand { func makeService() throws -> AppStoreConnectService { AppStoreConnectService(configuration: try APIConfiguration(common.authOptions)) @@ -23,7 +31,20 @@ struct CommonOptions: ParsableArguments { @Flag(default: .table, help: "Display results in specified format.") var outputFormat: OutputFormat - /// Used to print status messages. Defaults to `false`, except for `--table`, so all commands are parsable by default. + /// The verbosity of the executed command. + var printLevel: PrintLevel { + // Commands are parsable by default except for `--table` which is intended to be interactive. + switch (verbose, outputFormat == .table) { + // if `--verbose` or `--table`is used then return a verbose print level + case (true, _), (_, true): + return .verbose + // if both `--verbose` and `--table` are not used, then return a quiet print level + case (false, false): + return .quiet + } + } + + /// Used to define the command's `PrintLevel`. Defaults to `false`. @Flag(name: .shortAndLong, help: "Display extra messages as command is running.") var verbose: Bool } diff --git a/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift b/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift index aff660e6..33e9f85a 100755 --- a/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift @@ -31,8 +31,8 @@ struct SyncUsersCommand: CommonParsableCommand { var dryRun: Bool func run() throws { - // Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table` - if dryRun, common.verbose || common.outputFormat == .table { + // Only print if the `PrintLevel` is set to verbose. + if common.printLevel == .verbose { print("## Dry run ##") } From d53dae74309ebb2369dcc3408cdfe4f4f88e381e Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 25 Aug 2020 21:55:45 -0700 Subject: [PATCH 5/6] Cleanup --- .../AppStoreConnectCLI/Commands/CommonParsableCommand.swift | 2 +- .../Commands/Profiles/ListProfilesCommand.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift index 9462136a..e9310c49 100755 --- a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift @@ -10,7 +10,7 @@ protocol CommonParsableCommand: ParsableCommand { func makeService() throws -> AppStoreConnectService } -/// A level representing the verbosity of command. +/// A level representing the verbosity of a command. enum PrintLevel { // Withholds displaying normal status messages case quiet diff --git a/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift b/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift index 7f0e335d..565e2a43 100644 --- a/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift @@ -79,8 +79,8 @@ struct ListProfilesCommand: CommonParsableCommand { try profiles.forEach { let file = try processor.write($0) - // Command output is parsable by default. Only print if verbosity is enabled or output is a `.table` - if common.verbose || common.outputFormat == .table { + // Only print if the `PrintLevel` is set to verbose. + if common.printLevel == .verbose { print("📥 Profile '\($0.name!)' downloaded to: \(file.path)") } } From cdb7c325fb049f4428dc2c5728d8970b09905327 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 25 Aug 2020 22:50:59 -0700 Subject: [PATCH 6/6] Fixed swiftlint issues --- .../Commands/CommonParsableCommand.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift index e9310c49..e5caf60f 100755 --- a/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift +++ b/Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift @@ -35,12 +35,12 @@ struct CommonOptions: ParsableArguments { var printLevel: PrintLevel { // Commands are parsable by default except for `--table` which is intended to be interactive. switch (verbose, outputFormat == .table) { - // if `--verbose` or `--table`is used then return a verbose print level - case (true, _), (_, true): - return .verbose - // if both `--verbose` and `--table` are not used, then return a quiet print level - case (false, false): - return .quiet + // if `--verbose` or `--table`is used then return a verbose print level + case (true, _), (_, true): + return .verbose + // if both `--verbose` and `--table` are not used, then return a quiet print level + case (false, false): + return .quiet } }