Skip to content

Commit 62c9268

Browse files
committed
Merge pull request #371 from abertelrud/master
Invoking `swift package` with no options should show help
1 parent 9f8adc6 commit 62c9268

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Sources/Basic/OptionParser.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public enum OptionParserError: ErrorProtocol {
1818
case expectedAssociatedValue(String)
1919
case unexpectedAssociatedValue(String, String)
2020
case invalidUsage(String)
21+
case noCommandProvided(String)
2122
}
2223

2324
extension OptionParserError: CustomStringConvertible {
@@ -33,6 +34,8 @@ extension OptionParserError: CustomStringConvertible {
3334
return "unknown command: \(cmd)"
3435
case .invalidUsage(let hint):
3536
return "invalid usage: \(hint)"
37+
case .noCommandProvided(let hint):
38+
return "no command provided: \(hint)"
3639
}
3740
}
3841
}

Sources/Commands/Error.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@ extension Error: CustomStringConvertible {
5353
print("", to: &stderr)
5454
usage { print($0, to: &stderr) }
5555
}
56+
case OptionParserError.noCommandProvided(let hint):
57+
if !hint.isEmpty {
58+
print(error: error)
59+
}
60+
if isTTY(.stdErr) {
61+
usage { print($0, to: &stderr) }
62+
}
5663
case is OptionParserError:
5764
print(error: error)
5865
if isTTY(.stdErr) {
59-
let argv0 = Process.arguments.first ?? "swift build"
66+
let argv0 = Process.arguments.first ?? "swift package"
6067
print("enter `\(argv0) --help' for usage information", to: &stderr)
6168
}
6269
default:

Sources/Commands/SwiftPackageTool.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ public struct SwiftPackageTool {
287287
return (mode, opts)
288288
}
289289
else {
290-
throw OptionParserError.invalidUsage("no command provided: \(args)")
290+
// FIXME: This needs to produce a properly quoted string, once we have such API.
291+
throw OptionParserError.noCommandProvided(args.joined(separator: " "))
291292
}
292293
}
293294
}

0 commit comments

Comments
 (0)