Skip to content

Commit

Permalink
add option for xcode output
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Kahnert authored and Julian Kahnert committed Jun 29, 2020
1 parent 2232238 commit 3157329
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
19 changes: 16 additions & 3 deletions Sources/TerminalLog/TerminalLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public struct TerminalLog: LogHandler {
}
}
public var logLevel: Logger.Level = .info

private let xcodeOutput: Bool
private var prettyMetadata: String?

public init(_: String) { }
public init(xcodeOutput: Bool = false) {
self.xcodeOutput = xcodeOutput
}

public func log(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, file: String, function: String, line: UInt) {

Expand All @@ -37,7 +39,18 @@ public struct TerminalLog: LogHandler {
formedMessage += " -- " + combinedPrettyMetadata!
}

print("\(formedMessage, color: getColor(for: level))")
if xcodeOutput,
let filename = metadata?["file"]?.description,
let linenumber = metadata?["line"]?.description {

var typeId = ""
if let type = metadata?["rule_id"]?.description {
typeId = " (\(type))"
}
print("\(filename):\(linenumber):1: \(level.rawValue): \(message.description)\(typeId)")
} else {
print("\(formedMessage, color: getColor(for: level))")
}
}

/// Add, remove, or change the logging metadata.
Expand Down
17 changes: 12 additions & 5 deletions Sources/chia/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ import TerminalLog
import TSCUtility
import Files

// bootstrap logging
LoggingSystem.bootstrap(TerminalLog.init)
let logger = Logger(label: "chia-cli")

// parse command line argument
let parser = ArgumentParser(commandName: "chia",
usage: "[--config path] [--language-detection]",
usage: "[--config path] [--language-detection] [--xcode]",
overview: "Run several check like linting etc. in your CI process.")
let configPath: OptionArgument<String> = parser.add(option: "--config", shortName: "-c", kind: String.self, usage: "Path to the Config file (local or remote), e.g. 'https://PATH/TO/.chia.yml'", completion: .filename)
let onlyLanguageDetection: OptionArgument<Bool> = parser.add(option: "--language-detection", kind: Bool.self, usage: "Returns a project language for a given root folder. All checks will be skipped.")
let xcodeOutput: OptionArgument<Bool> = parser.add(option: "--xcode", kind: Bool.self, usage: "Returns output Xcode formatted.")

do {
let result = try parser.parse(Array(CommandLine.arguments.dropFirst()))

// bootstrap logging
LoggingSystem.bootstrap { input in
return TerminalLog(xcodeOutput: result.get(xcodeOutput) ?? false)
}

let logger = Logger(label: "chia-cli")

// setup chia
var chia = Chia(logger: logger)

Expand Down Expand Up @@ -51,12 +55,15 @@ do {
try chia.runChecks()
}
} catch ArgumentParserError.expectedValue(let value) {
let logger = Logger(label: "chia-cli")
logger.error("Missing value for argument \(value).")
exit(1)
} catch ArgumentParserError.expectedArguments(_, let stringArray) {
let logger = Logger(label: "chia-cli")
logger.error("Missing arguments: \(stringArray.joined()).")
exit(1)
} catch {
let logger = Logger(label: "chia-cli")
logger.error("\(error.localizedDescription)")
exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/chiaLib/Internal/CheckProviders/SwiftLintCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ struct SwiftLintCheck: CheckProvider {

return violatons.map { violation in
CheckResult(severity: violation.severity,
message: "\(violation.type) - \(violation.reason)",
metadata: ["file": .string(violation.file), "line": .stringConvertible(violation.line)])
message: violation.reason,
metadata: ["file": .string(violation.file), "line": .stringConvertible(violation.line), "rule_id": .string(violation.ruleID)])
}
}
}
Expand Down

0 comments on commit 3157329

Please sign in to comment.