mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-17 16:38:54 +00:00
parent
5b6a1d4713
commit
2bcf8813d3
8 changed files with 83 additions and 3 deletions
|
|
@ -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}",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue