mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-18 08:55:41 +00:00
* Comment style * IRecordTransformer -> RecordTransfomer * make fmt * else-return style mod * snake-case -> camel-case * Remove redundant err = nil and similar zero-value initializations. * redundant break; * bugfix * neaten * typofix * simplify/standardize init of zero-length slices * Standardize fmt.Fprintf w/ errors * fix double print of "mlr:" * neatening * Uniformize error messages * make docs * avoid shadowing package names * shorten some receiver names
36 lines
952 B
Go
36 lines
952 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// CheckArgCount is for flags with values, e.g. ["-n" "10"], while we're
|
|
// looking at the "-n": this let us see if the "10" slot exists.
|
|
func CheckArgCount(args []string, argi int, argc int, n int) {
|
|
if (argc - argi) < n {
|
|
fmt.Fprintf(os.Stderr, "%s: option \"%s\" missing argument(s).\n", "mlr", args[argi])
|
|
fmt.Fprintf(os.Stderr, "Please run \"%s --help\" for detailed usage information.\n", "mlr")
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
// SeparatorFromArg is for letting people do things like `--ifs pipe`
|
|
// rather than `--ifs '|'`.
|
|
func SeparatorFromArg(name string) string {
|
|
sep, ok := SEPARATOR_NAMES_TO_VALUES[name]
|
|
if ok {
|
|
return sep
|
|
}
|
|
return name
|
|
}
|
|
|
|
// SeparatorRegexFromArg is for letting people do things like `--ifs-regex whitespace`
|
|
// rather than `--ifs '([ \t])+'`.
|
|
func SeparatorRegexFromArg(name string) string {
|
|
sep, ok := SEPARATOR_REGEX_NAMES_TO_VALUES[name]
|
|
if ok {
|
|
return sep
|
|
}
|
|
return name
|
|
}
|