Skip to content

Commit

Permalink
Print a usage description when the user enters the swift-format comma…
Browse files Browse the repository at this point in the history
…nd without arguments
  • Loading branch information
TTOzzi committed Jan 11, 2025
1 parent 6e64b26 commit 6f3ef3a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/swift-format/Subcommands/Format.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 6f3ef3a

Please sign in to comment.