-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
main.swift
59 lines (50 loc) · 1.96 KB
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Foundation
import Logger
import RunnerLib
/// Version for showing in verbose mode
let DangerVersion = "3.20.0" // swiftlint:disable:this identifier_name
let MinimumDangerJSVersion = "6.1.6" // swiftlint:disable:this identifier_name
private func runCommand(_ command: DangerCommand, logger: Logger) throws {
switch command {
case .ci, .local, .pr:
let exitCode = try runDangerJSCommandToRunDangerSwift(command, logger: logger)
checkForUpdate(logger: logger)
exit(exitCode)
case .edit:
try editDanger(version: DangerVersion, logger: logger)
case .runner:
try runDanger(version: DangerVersion, logger: logger)
}
}
private func checkForUpdate(logger: Logger) {
let versionChecker = VersionChecker(logger: logger, env: ProcessInfo.processInfo.environment)
versionChecker.checkForUpdate(current: DangerVersion)
}
let cliLength = ProcessInfo.processInfo.arguments.count
let isVerbose = CommandLine.arguments.contains("--verbose") || (ProcessInfo.processInfo.environment["DEBUG"] != nil)
let isSilent = CommandLine.arguments.contains("--silent")
let logger = Logger(isVerbose: isVerbose, isSilent: isSilent)
guard !CommandLine.arguments.contains("--version") else {
logger.logInfo(DangerVersion)
exit(0)
}
do {
if cliLength > 1 {
logger.debug("Launching Danger Swift \(CommandLine.arguments[1]) (v\(DangerVersion))")
let command = DangerCommand(rawValue: CommandLine.arguments[1])
guard !CommandLine.arguments.contains("--help") else {
HelpMessagePresenter.showHelpMessage(command: command, logger: logger)
exit(0)
}
if command != nil {
try runCommand(command!, logger: logger)
} else {
fatalError("Danger Swift does not support this argument, it only handles ci, local, pr & edit'")
}
} else {
try runDanger(version: DangerVersion, logger: logger)
}
} catch {
logger.logError(error)
exit(1)
}