From 8dbd796f7835546cf50a72253bfa56164356ed7e Mon Sep 17 00:00:00 2001 From: Markus Chmelar Date: Wed, 20 Dec 2017 19:07:19 +0100 Subject: [PATCH] Print color legend in the help for outdated instead of every invocation --- Source/carthage/Formatting.swift | 28 ++++++++++------------------ Source/carthage/Outdated.swift | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Source/carthage/Formatting.swift b/Source/carthage/Formatting.swift index 5cef386b22..1e3472de4d 100644 --- a/Source/carthage/Formatting.swift +++ b/Source/carthage/Formatting.swift @@ -85,12 +85,20 @@ public struct ColorOptions: OptionsProtocol { } public static func evaluate(_ mode: CommandMode) -> Result> { + return self.evaluate(mode, additionalUsage: nil) + } + + public static func evaluate(_ mode: CommandMode, additionalUsage: String? = nil) -> Result> { + var usage = "whether to apply color and terminal formatting (one of 'auto', 'always', or 'never')" + if let additionalUsage = additionalUsage { + usage += "\n" + additionalUsage + } return curry(self.init) <*> mode <| Option( key: "color", defaultValue: ColorArgument.auto, - usage: "whether to apply color and terminal formatting (one of 'auto', 'always', or 'never')" - ) + usage: usage + ) } } @@ -114,20 +122,4 @@ extension ColorOptions.Formatting { } return Color.Wrap(foreground: update.color).wrap } - - public var legendForOutdatedCommand: String? { - guard self.isColorful else { return nil } - - let header = "Legend — • «what happens when you run `carthage update`»:\n" - return [OutdatedCommand.UpdateType.newest, .newer, .ineligible].reduce(into: header) { - let (color, explanation) = ($1.color, $1.explanation) - let tabs = String( - repeating: "\t", - count: color == .yellow || color == .magenta ? 1 : 2 - ) - let colorDescription = Color.Wrap(foreground: color) - .wrap("<" + String(describing: color) + ">") - $0.append(colorDescription + tabs + "• " + explanation + "\n") - } - } } diff --git a/Source/carthage/Outdated.swift b/Source/carthage/Outdated.swift index 180a8ccdb6..b6c137ae4b 100644 --- a/Source/carthage/Outdated.swift +++ b/Source/carthage/Outdated.swift @@ -33,6 +33,18 @@ public struct OutdatedCommand: CommandProtocol { return "Will not be updated because of the specified version in Cartfile." } } + + static var legend: String { + let header = "Legend — • «what happens when you run `carthage update`»:\n" + return header + [UpdateType.newest, .newer, .ineligible].map { + let (color, explanation) = ($0.color, $0.explanation) + let tabs = String( + repeating: "\t", + count: color == .yellow || color == .magenta ? 1 : 2 + ) + return "<" + String(describing: color) + ">" + tabs + "• " + explanation + }.joined(separator: "\n") + } } public struct Options: OptionsProtocol { @@ -53,7 +65,7 @@ public struct OutdatedCommand: CommandProtocol { <*> mode <| Option(key: "use-ssh", defaultValue: false, usage: "use SSH for downloading GitHub repositories") <*> mode <| Option(key: "verbose", defaultValue: false, usage: "include nested dependencies") <*> mode <| Option(key: "xcode-warnings", defaultValue: false, usage: "output Xcode compatible warning messages") - <*> ColorOptions.evaluate(mode) + <*> ColorOptions.evaluate(mode, additionalUsage: UpdateType.legend) <*> mode <| projectDirectoryOption } @@ -93,7 +105,6 @@ public struct OutdatedCommand: CommandProtocol { carthage.println(formatting.projectName(project.name) + " " + versionSummary) } } - formatting.legendForOutdatedCommand.map(carthage.println) } else { carthage.println("All dependencies are up to date.") }