diff --git a/README.md b/README.md index 8d1bef2..c905242 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ The CLI supports 3 operation modes: - 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 (`-in` flag) +* Stdin (just `-` or `/dev/stdin` argument) - Format the yaml data from `stdin` and output the result to `stdout` (NOTE: If providing paths as command line arguments, the flags must be specified before any paths) diff --git a/cmd/yamlfmt/main.go b/cmd/yamlfmt/main.go index e756951..56197bf 100644 --- a/cmd/yamlfmt/main.go +++ b/cmd/yamlfmt/main.go @@ -32,7 +32,6 @@ var ( source yaml and formatted yaml.`) dry *bool = flag.Bool("dry", false, `Perform a dry run; show the output of a formatting operation without performing it.`) - in *bool = flag.Bool("in", false, "Format yaml read from stdin and output to stdout") ) const defaultConfigName = ".yamlfmt" @@ -51,12 +50,14 @@ func run() error { op = command.OperationLint } else if *dry { op = command.OperationDry - } else if *in { - op = command.OperationStdin } else { op = command.OperationFormat } + if len(flag.Args()) == 1 && isStdin(flag.Args()[0]) { + op = command.OperationStdin + } + configData, err := readDefaultConfigFile() if err != nil { if errors.Is(err, os.ErrNotExist) { @@ -101,3 +102,7 @@ func readConfig(path string) (map[string]interface{}, error) { func getFullRegistry() *yamlfmt.Registry { return yamlfmt.NewFormatterRegistry(&basic.BasicFormatterFactory{}) } + +func isStdin(arg string) bool { + return arg == "-" || arg == "/dev/stdin" +}