Skip to content

Commit

Permalink
satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas von Dein committed Jan 14, 2025
1 parent 675a7dc commit ab21515
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions lib/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,60 +98,3 @@ func determineIO(conf *cfg.Config, args []string) (io.Reader, string, error) {

return filehandle, pattern, nil
}

func _determineIO(conf *cfg.Config, args []string) ([]io.Reader, string, error) {
var filehandles []io.Reader

var pattern string

var haveio bool

stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
// we're reading from STDIN, which takes precedence over file args
filehandles = append(filehandles, os.Stdin)

if len(args) > 0 {
// ignore any args > 1
pattern = args[0]
conf.Pattern = args[0] // used for colorization by printData()
}

haveio = true
} else if len(args) > 0 {
// there were args left, take a look
if args[0] == "-" {
// in traditional unix programs a dash denotes STDIN (forced)
filehandles = append(filehandles, os.Stdin)
haveio = true
} else {
if _, err := os.Stat(args[0]); err != nil {
// first one is not a file, consider it as regexp and
// shift arg list
pattern = args[0]
conf.Pattern = args[0] // used for colorization by printData()
args = args[1:]
}

if len(args) > 0 {
// consider any other args as files
for _, file := range args {
filehandle, err := os.OpenFile(file, os.O_RDONLY, RWRR)

if err != nil {
return nil, "", fmt.Errorf("failed to read input file %s: %w", file, err)
}

filehandles = append(filehandles, filehandle)
haveio = true
}
}
}
}

if !haveio {
return nil, "", errors.New("no file specified and nothing to read on stdin")
}

return filehandles, pattern, nil
}

0 comments on commit ab21515

Please sign in to comment.