Skip to content

Commit 6356aca

Browse files
committed
Print a usage description when the user enters the swift-format command without arguments
1 parent 6e64b26 commit 6356aca

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Diff for: Sources/swift-format/Subcommands/Format.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,15 @@ extension SwiftFormatCommand {
3636
var performanceMeasurementOptions: PerformanceMeasurementsOptions
3737

3838
func validate() throws {
39-
if inPlace && formatOptions.paths.isEmpty {
40-
throw ValidationError("'--in-place' is only valid when formatting files")
39+
if formatOptions.paths.isEmpty, formatOptions.assumeFilename == nil {
40+
throw ValidationError(
41+
"""
42+
No input files specified. Use one of the following:
43+
- Provide the path to a directory along with the '--recursive' option to format all Swift files within it.
44+
- Provide the path to a specific Swift source code file.
45+
Additionally, if you want to overwrite files in-place, use '--in-place'.
46+
"""
47+
)
4148
}
4249
}
4350

Diff for: Sources/swift-format/Subcommands/Lint.swift

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ extension SwiftFormatCommand {
3232
@OptionGroup(visibility: .hidden)
3333
var performanceMeasurementOptions: PerformanceMeasurementsOptions
3434

35+
func validate() throws {
36+
if lintOptions.paths.isEmpty, lintOptions.assumeFilename == nil {
37+
throw ValidationError(
38+
"""
39+
No input files specified. Use one of the following:
40+
- Provide the path to a directory along with the '--recursive' option to lint all Swift files within it.
41+
- Provide the path to a specific Swift source code file.
42+
"""
43+
)
44+
}
45+
}
46+
3547
func run() throws {
3648
try performanceMeasurementOptions.printingInstructionCountIfRequested {
3749
let frontend = LintFrontend(lintFormatOptions: lintOptions)

0 commit comments

Comments
 (0)