Add -pipe flag #294

Solved the problem of trying to read from STDIN and stopping on the way when running from CRON or AWS Lambda.
This commit is contained in:
Kota Kanbe
2017-01-24 00:21:56 +09:00
parent 49b4b8be22
commit 2d854cd64d
9 changed files with 71 additions and 41 deletions

View File

@@ -74,7 +74,7 @@ func lsValidJSONDirs() (dirs jsonDirs, err error) {
// jsonDir returns
// If there is an arg, check if it is a valid format and return the corresponding path under results.
// If passed via PIPE (such as history subcommand), return that path.
// If arg passed via PIPE (such as history subcommand), return that path.
// Otherwise, returns the path of the latest directory
func jsonDir(args []string) (string, error) {
var err error
@@ -98,8 +98,7 @@ func jsonDir(args []string) (string, error) {
}
// PIPE
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
if c.Conf.Pipe {
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return "", fmt.Errorf("Failed to read stdin: %s", err)