Add a --files option (#1426)

* mlr --files

* doc mods
This commit is contained in:
John Kerl 2023-11-11 19:09:02 -05:00 committed by GitHub
parent 5b6a1d4713
commit 2bcf8813d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 3 deletions

View file

@ -7,7 +7,9 @@
package cli
import (
"bufio"
"fmt"
"io"
"os"
"strings"
@ -2797,6 +2799,51 @@ var MiscFlagSection = FlagSection{
},
},
{
name: "--files",
arg: "{filename}",
help: "Use this to specify a file which itself contains, one per line, names of input files. May be used more than once.",
parser: func(args []string, argc int, pargi *int, options *TOptions) {
CheckArgCount(args, *pargi, argc, 2)
fileName := args[*pargi+1]
handle, err := os.Open(fileName)
if err != nil {
/// XXXX return false
fmt.Fprintln(os.Stderr, "mlr", err)
os.Exit(1)
}
defer handle.Close()
lineReader := bufio.NewReader(handle)
eof := false
lineno := 0
for !eof {
line, err := lineReader.ReadString('\n')
if err == io.EOF {
err = nil
eof = true
break
}
lineno++
if err != nil {
fmt.Fprintln(os.Stderr, "mlr", err)
os.Exit(1)
}
// This is how to do a chomp:
// TODO: handle \r\n with libified solution.
line = strings.TrimRight(line, "\n")
options.FileNames = append(options.FileNames, line)
}
*pargi += 2
},
},
{
name: "--ofmt",
arg: "{format}",