Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ struct ListCertificatesCommand: CommonParsableCommand {

let file = try certificateProcessor.write($0)

print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)")
// Command output is parsable by default. Only print if user is enabling verbosity or output is a `.table`
if common.verbose || common.outputFormat == .table {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to have to use common.verbose || common.outputFormat == .table quite a bit here.
What do you think about making verbose be Bool? (defaulting to nil) and then we can add a computed var either a Bool or enum to check.

Thinking along these lines:

// CommonParsableCommand.swift

enum PrintLevel {
  case quiet
  case verbose
}

// CommonOptions

var printLevel: PrintLevel {
  switch verbose {
    case true:
      return .verbose
    case false:
      return .quiet
    case nil:
      return common.outputFormat == .table ? .verbose : .quiet
  }
}

// Usage

if common.printLevel == .verbose {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this is a good suggestion and I'll make these changes with small tweaks. I'll leave verbose as a Bool and I'll resolve the common.outputFormat == .table ternary in the switch statement itself. Should look something like this:

// CommonOptions

var printLevel: PrintLevel {
  switch (verbose, outputFormat == .table) {
    case (true, _), (_, true):
      return .verbose
    case (false, false):
      return .quiet
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks @csjones

print("📥 Certificate '\($0.name ?? "")' downloaded to: \(file.path)")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ struct ReadCertificateCommand: CommonParsableCommand {

let file = try fileProcessor.write(certificate)

print("📥 Certificate '\(certificate.name ?? "")' downloaded to: \(file.path)")
// 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)")
}
}

certificate.render(format: common.outputFormat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ struct RevokeCertificatesCommand: CommonParsableCommand {
let service = try makeService()
_ = try service.revokeCertificates(serials: serials)

serials.forEach {
print("🚮 Certificate `\($0)` revoked.")
// 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.")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ 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.
@Flag(name: .shortAndLong, help: "Display extra messages as command is running.")
var verbose: Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ struct ListProfilesCommand: CommonParsableCommand {
try profiles.forEach {
let file = try processor.write($0)

print("📥 Profile '\($0.name!)' downloaded to: \(file.path)")
// 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)")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct SyncUsersCommand: CommonParsableCommand {
var dryRun: Bool

func run() throws {
if dryRun {
// 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 ##")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)!
}
Expand Down