Skip to content

Commit

Permalink
Check stdin in Before instead of Action.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: David Grisham <[email protected]>
  • Loading branch information
dgrisham committed Sep 11, 2018
1 parent ef6657d commit 46439dc
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ var RunCmd = cli.Command{
},
Before: func(c *cli.Context) error {
if c.NArg() == 0 {
finfo, err := os.Stdin.Stat()
if err != nil {
return err
}
if finfo.Size() == 0 && finfo.Mode()&os.ModeNamedPipe == 0 {
return fmt.Errorf("error: no command input and stdin is empty")
}
return c.Set("stdin", "true")
}
if present := isTerminatorPresent(c); present {
Expand All @@ -53,15 +60,6 @@ var RunCmd = cli.Command{

var reader io.Reader
if c.IsSet("stdin") {
finfo, err := os.Stdin.Stat()
if err != nil {
return err
}
if finfo.Size() == 0 && finfo.Mode()&os.ModeNamedPipe == 0 {
cli.ShowCommandHelp(c, "run")
fmt.Println()
return fmt.Errorf("error: no command input and stdin is empty")
}
reader = bufio.NewReader(os.Stdin)
} else {
var builder strings.Builder
Expand Down

0 comments on commit 46439dc

Please sign in to comment.