From 58e6c289b9494bc6f5674518c7a9f59ff9bc7194 Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Mon, 8 Nov 2021 13:59:48 +0530 Subject: [PATCH] feat(input)!: allow passing `-` as filename for STDIN --- pkg/input/input.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/input/input.go b/pkg/input/input.go index 0f1a3e2..0334f4b 100644 --- a/pkg/input/input.go +++ b/pkg/input/input.go @@ -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 {