Skip to content

Commit 96c0438

Browse files
authored
Merge pull request #44 from owenv/help-updates
Miscellaneous improvements to -help messages
2 parents 5bcc711 + 1cb7ca5 commit 96c0438

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ extension Driver {
556556
}
557557

558558
if parsedOptions.contains(.help) || parsedOptions.contains(.helpHidden) {
559-
optionTable.printHelp(usage: driverKind.usage, title: driverKind.title, includeHidden: parsedOptions.contains(.helpHidden))
559+
optionTable.printHelp(driverKind: driverKind, includeHidden: parsedOptions.contains(.helpHidden))
560560
return
561561
}
562562

Sources/SwiftDriver/Driver/DriverKind.swift

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,7 @@ public enum DriverKind {
2727

2828
extension DriverKind {
2929
public var usage: String {
30-
switch self {
31-
case .autolinkExtract:
32-
return "swift-autolink-extract"
33-
34-
case .batch:
35-
return "swiftc"
36-
37-
case .frontend:
38-
return "swift -frontend"
39-
40-
case .indent:
41-
return "swift-indent"
42-
43-
case .interactive:
44-
return "swift"
45-
46-
case .moduleWrap:
47-
return "swift-modulewrap"
48-
}
30+
usageArgs.joined(separator: " ")
4931
}
5032

5133
public var usageArgs: [String] {
@@ -88,4 +70,21 @@ extension DriverKind {
8870
return "Swift Module Wrapper"
8971
}
9072
}
73+
74+
public var seeAlsoHelpMessage: String? {
75+
switch self {
76+
case .interactive:
77+
return """
78+
SEE ALSO - PACKAGE MANAGER COMMANDS:
79+
"swift build" Build sources into binary products
80+
"swift package" Perform operations on Swift packages
81+
"swift run" Build and run an executable product
82+
"swift test" Build and run tests
83+
"""
84+
case .batch:
85+
return "SEE ALSO: swift build, swift run, swift package, swift test"
86+
default:
87+
return nil
88+
}
89+
}
9190
}

Sources/SwiftDriver/Options/OptionTable.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ public struct OptionTable {
2626

2727
extension OptionTable {
2828
/// Print help information to the terminal.
29-
public func printHelp(usage: String, title: String, includeHidden: Bool) {
29+
public func printHelp(driverKind: DriverKind, includeHidden: Bool) {
3030
print("""
31-
OVERVIEW: \(title)
31+
OVERVIEW: \(driverKind.title)
3232
33-
USAGE: \(usage)
33+
USAGE: \(driverKind.usage)
3434
3535
OPTIONS:
3636
""")
3737

3838
for option in options {
3939
if option.isAlias { continue }
4040
if option.isHelpHidden && !includeHidden { continue }
41+
guard option.isAccepted(by: driverKind) else { continue }
4142
guard let helpText = option.helpText else { continue }
4243

4344
let maxDisplayNameLength = 23
@@ -71,5 +72,8 @@ extension OptionTable {
7172
print(" \(leftPadding) \(helpText)")
7273
}
7374
}
75+
if let seeAlsoMessage = driverKind.seeAlsoHelpMessage {
76+
print("\n\(seeAlsoMessage)")
77+
}
7478
}
7579
}

0 commit comments

Comments
 (0)