Skip to content

Commit

Permalink
#94 fix stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
incu6us committed Oct 16, 2023
1 parent 85f8a62 commit b2651e7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ func main() {
return
}

originPath, err = filepath.Abs(originPath)
if err != nil {
log.Fatalf("Failed to get abs path: %+v\n", err)
if originPath != reviser.StandardInput {
originPath, err = filepath.Abs(originPath)
if err != nil {
log.Fatalf("Failed to get abs path: %+v\n", err)
}
}

var formattedOutput []byte
Expand Down Expand Up @@ -321,7 +323,9 @@ func main() {
}
}
file, _ := os.OpenFile(cacheFile, os.O_RDWR, os.ModePerm)
defer file.Close()
defer func() {
_ = file.Close()
}()
if err = file.Truncate(0); err != nil {
log.Fatalf("Failed file truncate: %+v\n", err)
}
Expand Down Expand Up @@ -379,7 +383,7 @@ func validateRequiredParam(filePath string) error {
stat, _ := os.Stdin.Stat()
if stat.Mode()&os.ModeNamedPipe == 0 {
// no data on stdin
return fmt.Errorf("-%s should be set", filePathArg)
return fmt.Errorf("no data on stdin")
}
}
return nil
Expand Down

0 comments on commit b2651e7

Please sign in to comment.