Skip to content

Commit

Permalink
nicer output
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerd committed May 26, 2022
1 parent 936eb8f commit 6664486
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions Plugins/AWSLambdaPackager/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,17 @@ struct AWSLambdaPackager: CommandPlugin {
guard let _output = data.flatMap({ String(data: $0, encoding: .utf8)?.trimmingCharacters(in: CharacterSet(["\n"])) }), !_output.isEmpty else {
return
}
if logLevel >= .output {

output += _output + "\n"

switch logLevel {
case .silent:
break
case .debug(let outputIndent), .output(let outputIndent):
print(String(repeating: " ", count: outputIndent), terminator: "")
print(_output)
fflush(stdout)
}
output += _output + "\n"
}

let pipe = Pipe()
Expand Down Expand Up @@ -359,13 +365,31 @@ private struct Configuration: CustomStringConvertible {
}
}

private enum ProcessLogLevel: Int, Comparable {
case silent = 0
case output = 1
case debug = 2
private enum ProcessLogLevel: Comparable {
case silent
case output(outputIndent: Int)
case debug(outputIndent: Int)

var naturalOrder: Int {
switch self {
case .silent:
return 0
case .output:
return 1
case .debug:
return 2
}
}

static var output: Self {
.output(outputIndent: 2)
}
static var debug: Self {
.debug(outputIndent: 2)
}

static func < (lhs: ProcessLogLevel, rhs: ProcessLogLevel) -> Bool {
lhs.rawValue < rhs.rawValue
lhs.naturalOrder < rhs.naturalOrder
}
}

Expand Down

0 comments on commit 6664486

Please sign in to comment.