Skip to content

CLI: don't crash if no mode selected, just print the USAGE #257

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
Jun 9, 2025
Merged
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
8 changes: 7 additions & 1 deletion Sources/SwiftJavaTool/SwiftJava.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ struct SwiftJava: AsyncParsableCommand {
}

mutating func run() async {
guard CommandLine.arguments.count > 1 else {
// there's no "default" command, print USAGE when no arguments/parameters are passed.
print("Must specify run mode.\n\(Self.helpMessage())")
return
}

print("[info][swift-java] Run: \(CommandLine.arguments.joined(separator: " "))")
print("[info][swift-java] Current work directory: \(URL(fileURLWithPath: "."))")
print("[info][swift-java] Module base directory: \(moduleBaseDir)")
Expand Down Expand Up @@ -230,7 +236,7 @@ struct SwiftJava: AsyncParsableCommand {
toolMode = .configuration(extraClasspath: input)
} else if fetch {
guard let input else {
fatalError("Mode -jar requires <input> path\n\(Self.helpMessage())")
fatalError("Mode 'fetch' requires <input> path\n\(Self.helpMessage())")
}
config = try JavaTranslator.readConfiguration(from: URL(fileURLWithPath: input))
guard let dependencies = config.dependencies else {
Expand Down