Skip to content

Commit

Permalink
feat(input)!: allow passing - as filename for STDIN
Browse files Browse the repository at this point in the history
  • Loading branch information
shivjm committed Nov 8, 2021
1 parent e11796a commit 58e6c28
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/input/input.go
Expand Up @@ -5,10 +5,17 @@ import (
"os"
)

// GetInput opens the file named in `args` if present, `os.Stdin` if not.
// GetInput opens and returns the file named in `args` if present,
// `os.Stdin` if not. The special file `-` can be passed explicitly to
// read from `Stdin`.
func GetInput(args []string) (*os.File, error) {
if len(args) == 1 {
name := args[0]

if name == "-" {
return os.Stdin, nil
}

f, err := os.Open(name)

if err != nil {
Expand Down

0 comments on commit 58e6c28

Please sign in to comment.