Skip to content

Miscellaneous improvements to -help messages #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ extension Driver {
}

if parsedOptions.contains(.help) || parsedOptions.contains(.helpHidden) {
optionTable.printHelp(usage: driverKind.usage, title: driverKind.title, includeHidden: parsedOptions.contains(.helpHidden))
optionTable.printHelp(driverKind: driverKind, includeHidden: parsedOptions.contains(.helpHidden))
return
}

Expand Down
37 changes: 18 additions & 19 deletions Sources/SwiftDriver/Driver/DriverKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,7 @@ public enum DriverKind {

extension DriverKind {
public var usage: String {
switch self {
case .autolinkExtract:
return "swift-autolink-extract"

case .batch:
return "swiftc"

case .frontend:
return "swift -frontend"

case .indent:
return "swift-indent"

case .interactive:
return "swift"

case .moduleWrap:
return "swift-modulewrap"
}
usageArgs.joined(separator: " ")
}

public var usageArgs: [String] {
Expand Down Expand Up @@ -88,4 +70,21 @@ extension DriverKind {
return "Swift Module Wrapper"
}
}

public var seeAlsoHelpMessage: String? {
switch self {
case .interactive:
return """
SEE ALSO - PACKAGE MANAGER COMMANDS:
"swift build" Build sources into binary products
"swift package" Perform operations on Swift packages
"swift run" Build and run an executable product
"swift test" Build and run tests
"""
case .batch:
return "SEE ALSO: swift build, swift run, swift package, swift test"
default:
return nil
}
}
}
10 changes: 7 additions & 3 deletions Sources/SwiftDriver/Options/OptionTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ public struct OptionTable {

extension OptionTable {
/// Print help information to the terminal.
public func printHelp(usage: String, title: String, includeHidden: Bool) {
public func printHelp(driverKind: DriverKind, includeHidden: Bool) {
print("""
OVERVIEW: \(title)
OVERVIEW: \(driverKind.title)

USAGE: \(usage)
USAGE: \(driverKind.usage)

OPTIONS:
""")

for option in options {
if option.isAlias { continue }
if option.isHelpHidden && !includeHidden { continue }
guard option.isAccepted(by: driverKind) else { continue }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still meant to be in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this is ok. As far as I can tell the current version of the acceptance check only fails to reject some invalid options, it doesn’t reject any valid ones.

guard let helpText = option.helpText else { continue }

let maxDisplayNameLength = 23
Expand Down Expand Up @@ -71,5 +72,8 @@ extension OptionTable {
print(" \(leftPadding) \(helpText)")
}
}
if let seeAlsoMessage = driverKind.seeAlsoHelpMessage {
print("\n\(seeAlsoMessage)")
}
}
}