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.") }