Skip to content

Commit b67508e

Browse files
committed
fix: support flags output for ANSI
See 2372ad1 for more details
1 parent abd2f06 commit b67508e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Sources/Commander/ArgumentDescription.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,13 @@ class Help : Error, ANSIConvertible, CustomStringConvertible {
452452
if !options.isEmpty {
453453
output.append("Options:")
454454
for option in options {
455-
var line = " \(ANSI.blue)--\(option.name)\(ANSI.reset)"
455+
var line = " "
456+
457+
if let flag = option.flag {
458+
line += "\(ANSI.blue)-\(flag)\(ANSI.reset), "
459+
}
460+
461+
line += "\(ANSI.blue)--\(option.name)\(ANSI.reset)"
456462

457463
if let `default` = option.default {
458464
line += " [default: \(`default`)]"

Tests/CommanderTests/ArgumentDescriptionSpec.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ let testArgumentDescription: ((ContextType) -> Void) = {
8383
try expect(help.description) == "Options:\n -v, --verbose [default: false] - enable verbose mode"
8484
}
8585

86+
$0.it("shows option flag with ansi") {
87+
let help = Help([
88+
BoxedArgumentDescriptor(value: Flag("verbose", flag: "v", description: "enable verbose mode")),
89+
])
90+
91+
try expect(help.ansiDescription) == "Options:\n \(ANSI.blue)-v\(ANSI.reset), \(ANSI.blue)--verbose\(ANSI.reset) [default: false] - enable verbose mode"
92+
}
93+
8694
$0.it("shows default for custom types conforming to CustomStringConvertible") {
8795
enum Direction: String, CustomStringConvertible, ArgumentConvertible {
8896
case north

0 commit comments

Comments
 (0)