From 6f3ef3a6ac39443a7b0c4f7fec091246c5d344d8 Mon Sep 17 00:00:00 2001 From: TTOzzi Date: Sun, 12 Jan 2025 06:27:05 +0900 Subject: [PATCH] Print a usage description when the user enters the swift-format command without arguments --- Sources/swift-format/Subcommands/Format.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sources/swift-format/Subcommands/Format.swift b/Sources/swift-format/Subcommands/Format.swift index 42c2da16..5ac3ff17 100644 --- a/Sources/swift-format/Subcommands/Format.swift +++ b/Sources/swift-format/Subcommands/Format.swift @@ -36,6 +36,16 @@ extension SwiftFormatCommand { var performanceMeasurementOptions: PerformanceMeasurementsOptions func validate() throws { + if formatOptions.paths.isEmpty && !inPlace { + throw ValidationError( + """ + No input files specified. Use one of the following: + - Provide the path to a directory along with the '--recursive' option to format all Swift files within it. + - Provide the path to a specific Swift source code file. + And use '--in-place' to overwrite files in-place. + """ + ) + } if inPlace && formatOptions.paths.isEmpty { throw ValidationError("'--in-place' is only valid when formatting files") }