mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-16 20:20:57 +01:00
satisfy linter
This commit is contained in:
57
lib/io.go
57
lib/io.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user