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 12, 2025
1 parent 6e64b26 commit d4c9aa0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/swift-format/Subcommands/Format.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ extension SwiftFormatCommand {
var performanceMeasurementOptions: PerformanceMeasurementsOptions

func validate() throws {
if inPlace && formatOptions.paths.isEmpty {
throw ValidationError("'--in-place' is only valid when formatting files")
if formatOptions.paths.isEmpty, formatOptions.assumeFilename == nil {
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.
"""
)
}
}

Expand Down
12 changes: 12 additions & 0 deletions Sources/swift-format/Subcommands/Lint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ extension SwiftFormatCommand {
@OptionGroup(visibility: .hidden)
var performanceMeasurementOptions: PerformanceMeasurementsOptions

func validate() throws {
if lintOptions.paths.isEmpty, lintOptions.assumeFilename == nil {
throw ValidationError(
"""
No input files specified. Use one of the following:
- Provide the path to a directory along with the '--recursive' option to lint all Swift files within it.
- Provide the path to a specific Swift source code file.
"""
)
}
}

func run() throws {
try performanceMeasurementOptions.printingInstructionCountIfRequested {
let frontend = LintFrontend(lintFormatOptions: lintOptions)
Expand Down

0 comments on commit d4c9aa0

Please sign in to comment.