diff --git a/README.md b/README.md index 70b54f4..d8feed2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/yamlfmt/flags.go b/cmd/yamlfmt/flags.go index d9b7a57..9fd6dbc 100644 --- a/cmd/yamlfmt/flags.go +++ b/cmd/yamlfmt/flags.go @@ -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 { @@ -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" }