Allow setting input file when reading from STDIN #82
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #51. Alternative to #65.
This adds a new
--stdin-input-file FILE
command-line option. It is intended to be used when reading a Cabal file from STDIN. The givenFILE
will be used to resolve relative references, which allows pragmas like-- cabal-fmt: expand some-directory
to work even when reading from STDIN.I borrowed the flag name from Ormolu. I'm not set on it — if there's a better name, let's change it.
Like #65, this does not let you set both
--stdin-input-file
and an actual input file. In other words,cabal-fmt --stdin-input-file x y
is an error, even ifx
andy
happen to be the same.I think this is preferable to #65 because it should be easier to integrate with tools. It's very common to have the file path of the file you want to format, along with the file's contents in memory. Requiring a directory name would require calling something like
dirname
, which is just an extra unnecessary step.