Skip to content

Commit

Permalink
Add verbose flag for additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardiman committed Sep 24, 2019
1 parent 644cda5 commit 50f9377
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/Config/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct Arguments {
let scheme: String
let configURL: URL
let additionalExtension: String?
let verbose: Bool
}

extension Arguments {
Expand All @@ -20,8 +21,9 @@ extension Arguments {
case scheme = "--scheme"
case configPath = "--configPath"
case additionalExtension = "--ext"
case verbose = "--verbose"

static let all: [Option] = [.scheme, .configPath, .additionalExtension]
static let all: [Option] = [.scheme, .configPath, .additionalExtension, .verbose]

var usage: String {
switch self {
Expand All @@ -31,6 +33,8 @@ extension Arguments {
return "\(rawValue)\t\t(Required) The path to the configuration files"
case .additionalExtension:
return "\(rawValue)\t\t(Optional) An additional extension slug to add before .swift in the output files. Useful for .gitignore"
case .verbose:
return "\(rawValue)\t\t(Optional) Should extra logging be output?"
}
}
}
Expand Down Expand Up @@ -60,6 +64,7 @@ extension Arguments {
self.scheme = scheme
self.configURL = URL(fileURLWithPath: configPath)
self.additionalExtension = argumentPairs[.additionalExtension]
self.verbose = argumentPairs[.verbose] ?? false
}
}

Expand Down
6 changes: 6 additions & 0 deletions Sources/Config/ConfigGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class ConfigGenerator {
]

try configFiles.forEach { url in
if arguments.verbose, let configFileValue = try? String(contentsOf: url) {
printer.print(message: "Processing config file \(configFileValue)")
}
guard let config = dictionaryFromJSON(at: url) else {
throw ConfigError.badJSON
}
Expand All @@ -43,6 +46,9 @@ public class ConfigGenerator {
let newData = configurationFile.description
var shouldWrite = true
if let currentData = try? String(contentsOf: swiftOutput) {
if arguments.verbose {
printer.print(message: "Existing file contents: \(currentData)")
}
if newData == currentData {
shouldWrite = false
} else {
Expand Down

0 comments on commit 50f9377

Please sign in to comment.