Skip to content

Commit f9b10f2

Browse files
authored
Merge pull request #914 from TTOzzi/more-friendly-commands
Gradually deprecate running swift-format without input paths; require '-' for stdin in the future
2 parents c0b518e + 3f041ed commit f9b10f2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Sources/swift-format/Frontend/Frontend.swift

+17-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,23 @@ class Frontend {
9797

9898
/// Runs the linter or formatter over the inputs.
9999
final func run() {
100-
if lintFormatOptions.paths.isEmpty {
100+
if lintFormatOptions.paths == ["-"] {
101+
processStandardInput()
102+
} else if lintFormatOptions.paths.isEmpty {
103+
diagnosticsEngine.emitWarning(
104+
"""
105+
Running swift-format without input paths is deprecated and will be removed in the future.
106+
107+
Please update your invocation to do either of the following:
108+
109+
- Pass `-` to read from stdin (e.g., `cat MyFile.swift | swift-format -`).
110+
- Pass one or more paths to Swift source files or directories containing
111+
Swift source files. When passing directories, make sure to include the
112+
`--recursive` flag.
113+
114+
For more information, use the `--help` option.
115+
"""
116+
)
101117
processStandardInput()
102118
} else {
103119
processURLs(

Sources/swift-format/Subcommands/LintFormatOptions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct LintFormatOptions: ParsableArguments {
108108
var experimentalFeatures: [String] = []
109109

110110
/// The list of paths to Swift source files that should be formatted or linted.
111-
@Argument(help: "Zero or more input filenames.")
111+
@Argument(help: "Zero or more input filenames. Use `-` for stdin.")
112112
var paths: [String] = []
113113

114114
@Flag(help: .hidden) var debugDisablePrettyPrint: Bool = false

0 commit comments

Comments
 (0)