Skip to content

Commit c176752

Browse files
Merge pull request #220 from csjones/csjones-quiet
Adding a verbose flag for displaying more messages in terminal
2 parents e3dfede + cdb7c32 commit c176752

File tree

7 files changed

+47
-7
lines changed

7 files changed

+47
-7
lines changed

Sources/AppStoreConnectCLI/Commands/Certificates/ListCertificatesCommand.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ struct ListCertificatesCommand: CommonParsableCommand {
5555

5656
let file = try certificateProcessor.write($0)
5757

58-
print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)")
58+
// Only print if the `PrintLevel` is set to verbose.
59+
if common.printLevel == .verbose {
60+
print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)")
61+
}
5962
}
6063
}
6164

Sources/AppStoreConnectCLI/Commands/Certificates/ReadCertificateCommand.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ struct ReadCertificateCommand: CommonParsableCommand {
2828

2929
let file = try fileProcessor.write(certificate)
3030

31-
print("📥 Certificate '\(certificate.name ?? "")' downloaded to: \(file.path)")
31+
// Only print if the `PrintLevel` is set to verbose.
32+
if common.printLevel == .verbose {
33+
print("📥 Certificate '\(certificate.name ?? "")' downloaded to: \(file.path)")
34+
}
3235
}
3336

3437
certificate.render(format: common.outputFormat)

Sources/AppStoreConnectCLI/Commands/Certificates/RevokeCertificatesCommand.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ struct RevokeCertificatesCommand: CommonParsableCommand {
2525
let service = try makeService()
2626
_ = try service.revokeCertificates(serials: serials)
2727

28-
serials.forEach {
29-
print("🚮 Certificate `\($0)` revoked.")
28+
// Only print if the `PrintLevel` is set to verbose.
29+
if common.printLevel == .verbose {
30+
serials.forEach {
31+
print("🚮 Certificate `\($0)` revoked.")
32+
}
3033
}
3134
}
3235

Sources/AppStoreConnectCLI/Commands/CommonParsableCommand.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ protocol CommonParsableCommand: ParsableCommand {
1010
func makeService() throws -> AppStoreConnectService
1111
}
1212

13+
/// A level representing the verbosity of a command.
14+
enum PrintLevel {
15+
// Withholds displaying normal status messages
16+
case quiet
17+
// Displays all status messages
18+
case verbose
19+
}
20+
1321
extension CommonParsableCommand {
1422
func makeService() throws -> AppStoreConnectService {
1523
AppStoreConnectService(configuration: try APIConfiguration(common.authOptions))
@@ -22,4 +30,21 @@ struct CommonOptions: ParsableArguments {
2230

2331
@Flag(default: .table, help: "Display results in specified format.")
2432
var outputFormat: OutputFormat
33+
34+
/// The verbosity of the executed command.
35+
var printLevel: PrintLevel {
36+
// Commands are parsable by default except for `--table` which is intended to be interactive.
37+
switch (verbose, outputFormat == .table) {
38+
// if `--verbose` or `--table`is used then return a verbose print level
39+
case (true, _), (_, true):
40+
return .verbose
41+
// if both `--verbose` and `--table` are not used, then return a quiet print level
42+
case (false, false):
43+
return .quiet
44+
}
45+
}
46+
47+
/// Used to define the command's `PrintLevel`. Defaults to `false`.
48+
@Flag(name: .shortAndLong, help: "Display extra messages as command is running.")
49+
var verbose: Bool
2550
}

Sources/AppStoreConnectCLI/Commands/Profiles/ListProfilesCommand.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ struct ListProfilesCommand: CommonParsableCommand {
7979
try profiles.forEach {
8080
let file = try processor.write($0)
8181

82-
print("📥 Profile '\($0.name!)' downloaded to: \(file.path)")
82+
// Only print if the `PrintLevel` is set to verbose.
83+
if common.printLevel == .verbose {
84+
print("📥 Profile '\($0.name!)' downloaded to: \(file.path)")
85+
}
8386
}
8487
}
8588

Sources/AppStoreConnectCLI/Commands/Users/SyncUsersCommand.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ struct SyncUsersCommand: CommonParsableCommand {
3131
var dryRun: Bool
3232

3333
func run() throws {
34-
if dryRun {
34+
// Only print if the `PrintLevel` is set to verbose.
35+
if common.printLevel == .verbose {
3536
print("## Dry run ##")
3637
}
3738

Sources/AppStoreConnectCLI/Readers and Renderers/Renderers.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ protocol ResultRenderable: Codable {
5555
extension ResultRenderable {
5656
func renderAsJSON() -> String {
5757
let jsonEncoder = JSONEncoder()
58-
jsonEncoder.outputFormatting = [.prettyPrinted, .sortedKeys]
58+
// Withholding `.prettyPrinted` to maintain output that is parsable by default.
59+
// Consider adding the option `--pretty` if needed https://github.com/ittybittyapps/appstoreconnect-cli/issues/221
60+
jsonEncoder.outputFormatting = [.sortedKeys]
5961
let json = try! jsonEncoder.encode(self) // swiftlint:disable:this force_try
6062
return String(data: json, encoding: .utf8)!
6163
}

0 commit comments

Comments
 (0)