From 3913ed8e357bfd9d096a0ce0aa631162b62bd11e Mon Sep 17 00:00:00 2001 From: Konrad 'ktoso' Malawski Date: Mon, 9 Jun 2025 16:07:17 +0900 Subject: [PATCH] CLI: don't crash if no mode selected, just print the USAGE --- Sources/SwiftJavaTool/SwiftJava.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftJavaTool/SwiftJava.swift b/Sources/SwiftJavaTool/SwiftJava.swift index badd5455..a0ba75dc 100644 --- a/Sources/SwiftJavaTool/SwiftJava.swift +++ b/Sources/SwiftJavaTool/SwiftJava.swift @@ -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)") @@ -230,7 +236,7 @@ struct SwiftJava: AsyncParsableCommand { toolMode = .configuration(extraClasspath: input) } else if fetch { guard let input else { - fatalError("Mode -jar requires path\n\(Self.helpMessage())") + fatalError("Mode 'fetch' requires path\n\(Self.helpMessage())") } config = try JavaTranslator.readConfiguration(from: URL(fileURLWithPath: input)) guard let dependencies = config.dependencies else {