Skip to content

Commit ea6087b

Browse files
committed
Miscellaneous improvements to -help messages
1 parent 4efb328 commit ea6087b

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ extension Driver {
552552
}
553553

554554
if parsedOptions.contains(.help) || parsedOptions.contains(.helpHidden) {
555-
optionTable.printHelp(usage: driverKind.usage, title: driverKind.title, includeHidden: parsedOptions.contains(.helpHidden))
555+
optionTable.printHelp(driverKind: driverKind, includeHidden: parsedOptions.contains(.helpHidden))
556556
return
557557
}
558558

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/Option.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extension Option {
137137
return attributes.contains(.autolinkExtract)
138138

139139
case .batch:
140-
return !attributes.contains(.noBatch)
140+
return !attributes.contains(.noBatch) && !attributes.contains(.noDriver)
141141

142142
case .frontend:
143143
return attributes.contains(.frontend)
@@ -146,7 +146,7 @@ extension Option {
146146
return attributes.contains(.indent)
147147

148148
case .interactive:
149-
return !attributes.contains(.noInteractive)
149+
return !attributes.contains(.noInteractive) && !attributes.contains(.noDriver)
150150

151151
case .moduleWrap:
152152
return attributes.contains(.moduleWrap)

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)