Skip to content

Commit 0ad2a0a

Browse files
committed
Add colors to the output of Outdated
1 parent 1628d43 commit 0ad2a0a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Source/carthage/Formatting.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public struct ColorOptions: OptionsProtocol {
7777
func quote(_ string: String, quotationMark: String = "\"") -> String {
7878
return wrap(isColorful, wrap: Color.Wrap(foreground: .green))(quotationMark + string + quotationMark)
7979
}
80+
81+
/// Wraps a string in a color
82+
func colored(_ string: String, color: Color.Named.Color) -> String {
83+
return wrap(isColorful, wrap: Color.Wrap(foreground: color))(string)
84+
}
8085
}
8186

8287
private init(argument: ColorArgument) {

Source/carthage/Outdated.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Foundation
44
import Result
55
import ReactiveSwift
66
import Curry
7+
import PrettyColors
78

89
/// Type that encapsulates the configuration and evaluation of the `outdated` subcommand.
910
public struct OutdatedCommand: CommandProtocol {
@@ -54,13 +55,40 @@ public struct OutdatedCommand: CommandProtocol {
5455

5556
if !outdatedDependencies.isEmpty {
5657
carthage.println(formatting.path("The following dependencies are outdated:"))
58+
5759
for (project, current, updated, latest) in outdatedDependencies {
60+
let versionColor: Color.Named.Color
61+
switch (current, updated, latest) {
62+
case (_, updated, latest) where updated == latest:
63+
// Update available and applicable
64+
versionColor = .green
65+
case (current, updated, latest) where current != updated && updated != latest:
66+
// Update availabe and applicable, but not to the latest version due to version lock
67+
versionColor = .yellow
68+
case (current, updated, latest) where current == updated:
69+
// Update available, but not applicable due to version lock
70+
versionColor = .red
71+
default:
72+
versionColor = .white
73+
}
74+
5875
if options.outputXcodeWarnings {
5976
carthage.println("warning: \(formatting.projectName(project.name)) is out of date (\(current) -> \(updated)) (Latest: \(latest))")
6077
} else {
61-
carthage.println(formatting.projectName(project.name) + " \(current) -> \(updated) (Latest: \(latest))")
78+
let versionSummary = formatting.colored(current.description, color: versionColor)
79+
+ " -> " + formatting.colored(updated.description, color: versionColor)
80+
+ " (Latest: \(latest))"
81+
carthage.println(formatting.projectName(project.name) + " " + versionSummary)
6282
}
6383
}
84+
85+
if options.colorOptions.formatting.isColorful {
86+
carthage.println(formatting.path("The color indicates what happens when you run `carthage update`"))
87+
carthage.println(formatting.colored("<green>", color: .green) + "\t\t- Will be updated to the newest version")
88+
carthage.println(formatting.colored("<yellow>", color: .yellow) + "\t- Will be updated, but not to the newest version"
89+
+ " because of the specified version in Cartfile")
90+
carthage.println(formatting.colored("<red>", color: .red) + "\t\t- Will not be updated because of the specified version in Cartfile")
91+
}
6492
} else {
6593
carthage.println("All dependencies are up to date.")
6694
}

0 commit comments

Comments
 (0)