-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
673 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
skippedProviders: | ||
# - ReadmeCheck | ||
# - LicenseCheck | ||
# - SwiftLintCheck | ||
|
||
projectRootAppendix: Null | ||
|
||
swiftLintConfig: | ||
lintingRulesPath: https://PATH/TO/CONFIG/.swiftlint.yml | ||
# lintingRulesPath: /LOCAL/PATH/TO/CONFIG/.swiftlint.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
.swiftlint.yml | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// ASCIIColor.swift | ||
// | ||
// | ||
// Created by Julian Kahnert on 16.01.20. | ||
// | ||
// Source: https://stackoverflow.com/a/56510700/10026834 | ||
|
||
enum ASCIIColor: String { | ||
case black = "\u{001B}[0;30m" | ||
case red = "\u{001B}[0;31m" | ||
case green = "\u{001B}[0;32m" | ||
case yellow = "\u{001B}[0;33m" | ||
case blue = "\u{001B}[0;34m" | ||
case magenta = "\u{001B}[0;35m" | ||
case cyan = "\u{001B}[0;36m" | ||
case white = "\u{001B}[0;37m" | ||
case `default` = "\u{001B}[0;0m" | ||
} | ||
|
||
extension DefaultStringInterpolation { | ||
mutating func appendInterpolation<T: CustomStringConvertible>(_ value: T, color: ASCIIColor) { | ||
appendInterpolation("\(color.rawValue)\(value)\(ASCIIColor.default.rawValue)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// TerminalLog.swift | ||
// | ||
// | ||
// Created by Julian Kahnert on 16.01.20. | ||
// | ||
// Source: https://github.com/chrisaljoudi/swift-log-oslog | ||
|
||
import Logging | ||
|
||
public struct TerminalLog: LogHandler { | ||
|
||
public var metadata = Logger.Metadata() { | ||
didSet { | ||
self.prettyMetadata = self.prettify(self.metadata) | ||
} | ||
} | ||
public var logLevel: Logger.Level = .info | ||
|
||
private var prettyMetadata: String? | ||
|
||
public init(_: String) { } | ||
|
||
public func log(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, file: String, function: String, line: UInt) { | ||
|
||
var combinedPrettyMetadata = self.prettyMetadata | ||
if let metadataOverride = metadata, !metadataOverride.isEmpty { | ||
combinedPrettyMetadata = self.prettify( | ||
self.metadata.merging(metadataOverride) { | ||
return $1 | ||
} | ||
) | ||
} | ||
|
||
var formedMessage = message.description | ||
if combinedPrettyMetadata != nil { | ||
formedMessage += " -- " + combinedPrettyMetadata! | ||
} | ||
|
||
print("\(formedMessage, color: getColor(for: level))\n") | ||
} | ||
|
||
/// Add, remove, or change the logging metadata. | ||
/// - parameters: | ||
/// - metadataKey: the key for the metadata item. | ||
public subscript(metadataKey metadataKey: String) -> Logger.Metadata.Value? { | ||
get { | ||
return self.metadata[metadataKey] | ||
} | ||
set { | ||
self.metadata[metadataKey] = newValue | ||
} | ||
} | ||
|
||
private func prettify(_ metadata: Logger.Metadata) -> String? { | ||
if metadata.isEmpty { | ||
return nil | ||
} | ||
return metadata.map { | ||
"\($0)=\($1)" | ||
}.joined(separator: " ") | ||
} | ||
|
||
private func getColor(for level: Logger.Level) -> ASCIIColor { | ||
let color: ASCIIColor | ||
switch level { | ||
case .critical, .error: | ||
color = .red | ||
case .warning: | ||
color = .yellow | ||
case .info: | ||
color = .green | ||
default: | ||
color = .default | ||
} | ||
return color | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,63 @@ | ||
// swiftlint:disable line_length | ||
|
||
import chiaLib | ||
import Foundation | ||
#if canImport(FoundationNetworking) | ||
import FoundationNetworking | ||
#endif | ||
import Logging | ||
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: "[--only-language-detection]", | ||
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: "--only-language-detection", kind: Bool.self) | ||
|
||
do { | ||
try Chia.runChecks() | ||
let result = try parser.parse(Array(CommandLine.arguments.dropFirst())) | ||
|
||
// setup chia | ||
var chia = Chia(logger: logger) | ||
|
||
// try to get a config path from the CLI - use default config otherwise | ||
if let configPath = result.get(configPath) { | ||
|
||
guard let url = URL(localOrRemotePath: configPath) else { | ||
logger.error("Could not find a config at:\n\(configPath)") | ||
exit(1) | ||
} | ||
try chia.setConfig(from: url) | ||
} else { | ||
|
||
// no url is provied - use the default one | ||
try chia.setConfig(from: nil) | ||
} | ||
|
||
if result.get(onlyLanguageDetection) ?? false { | ||
if let detectedLanguage = chia.detectProjectLanguage() { | ||
logger.info("Language: \(detectedLanguage)") | ||
} else { | ||
logger.warning("No language detected.") | ||
} | ||
} else { | ||
try chia.runChecks() | ||
} | ||
} catch ArgumentParserError.expectedValue(let value) { | ||
logger.error("Missing value for argument \(value).") | ||
exit(1) | ||
} catch ArgumentParserError.expectedArguments(_, let stringArray) { | ||
logger.error("Missing arguments: \(stringArray.joined()).") | ||
exit(1) | ||
} catch { | ||
print(error) | ||
logger.error("\(error.localizedDescription)") | ||
exit(1) | ||
} | ||
exit(0) |
Oops, something went wrong.