Skip to content

Commit

Permalink
Print color legend in the help for outdated instead of every invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
iv-mexx committed Dec 20, 2017
1 parent 37b88fc commit 8dbd796
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
28 changes: 10 additions & 18 deletions Source/carthage/Formatting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,20 @@ public struct ColorOptions: OptionsProtocol {
}

public static func evaluate(_ mode: CommandMode) -> Result<ColorOptions, CommandantError<CarthageError>> {
return self.evaluate(mode, additionalUsage: nil)
}

public static func evaluate(_ mode: CommandMode, additionalUsage: String? = nil) -> Result<ColorOptions, CommandantError<CarthageError>> {
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
)
}
}

Expand All @@ -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 — <color> • «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")
}
}
}
15 changes: 13 additions & 2 deletions Source/carthage/Outdated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 — <color> • «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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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.")
}
Expand Down

0 comments on commit 8dbd796

Please sign in to comment.