Skip to content

Commit

Permalink
Restore in flag (#33)
Browse files Browse the repository at this point in the history
* fix: restore functionality of -in flag

Originally I had changed the read from stdin to be specified by a single
- argument or /dev/stdin by suggestion from #26. In that PR I had
removed the -in flag. After sleeping on it I realized I might as well
keep that flag, since it might intuitively make sense to more people,
makes more sense on Windows, and maintains backwards compatibility (even
though that is currently not a promise of the project, might as well do
it if it's easy).

* docs: add -in flag back to README
  • Loading branch information
braydonk committed Aug 25, 2022
1 parent fe69346 commit 9aa43f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The CLI supports the following flags/arguments:
- Format the matched files and output the diff to `stdout`
* Lint (`-lint` flag)
- Format the matched files and output the diff to `stdout`, exits with status 1 if there are any differences
* Stdin (just `-` or `/dev/stdin` argument)
* Stdin (just `-` or `/dev/stdin` argument, or `-in` flag)
- Format the yaml data from `stdin` and output the result to `stdout`
* Custom config path (`-conf` flag)
- If you would like to use a config not stored at `.yamlfmt` in the working directory, you can pass a relative or absolute path to a separate configuration file
Expand Down
9 changes: 7 additions & 2 deletions cmd/yamlfmt/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ var (
source yaml and formatted yaml.`)
flagDry *bool = flag.Bool("dry", false, `Perform a dry run; show the output of a formatting
operation without performing it.`)
flagIn *bool = flag.Bool("in", false, "Format yaml read from stdin and output to stdout")
flagConf *string = flag.String("conf", "", "Read yamlfmt config from this path")
)

func getOperation() command.Operation {
if len(flag.Args()) == 1 && isStdin(flag.Args()[0]) {
if *flagIn || isStdinArg() {
return command.OperationStdin
}
if *flagLint {
Expand All @@ -44,7 +45,11 @@ func getOperation() command.Operation {
return command.OperationFormat
}

func isStdin(arg string) bool {
func isStdinArg() bool {
if len(flag.Args()) != 1 {
return false
}
arg := flag.Args()[0]
return arg == "-" || arg == "/dev/stdin"
}

Expand Down

0 comments on commit 9aa43f4

Please sign in to comment.