miller/go/src/cli/mlrcli_util.go
John Kerl abe061e408
Flags lookup-table and doc autogen (#655)
* Tableize flag-parsing for on-line help, doc autogen, etc.

* Rename cli,cliutil packages -> climain,cli

* stub for new flag-list page

* Fix alignment & formatting for webdoc/manpage autogen

* per-flag-section info in mlr help

* Fix comparison of actual vs expected stderr file in regtest

* Replace old flag-parser with new
2021-09-08 22:16:40 -04:00

64 lines
1.4 KiB
Go

package cli
import (
"fmt"
"os"
"mlr/src/lib"
)
// 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)
}
}
// ----------------------------------------------------------------
var SEPARATOR_NAMES_TO_VALUES = map[string]string{
"colon": ":",
"comma": ",",
"cr": "\r",
"crcr": "\r\r",
"crlf": "\r\n",
"crlfcrlf": "\r\n\r\n",
"equals": "=",
"lf": "\n",
"lflf": "\n\n",
"newline": "\n",
"pipe": "|",
"semicolon": ";",
"slash": "/",
"space": " ",
"tab": "\t",
}
var SEPARATOR_NAMES_TO_VALUES_FOR_ONLINE_HELP = map[string]string{
"colon": ":",
"comma": ",",
"cr": "\\r",
"crcr": "\\r\\r",
"crlf": "\\r\\n",
"crlfcrlf": "\\r\\n\\r\\n",
"equals": "=",
"lf": "\\n",
"lflf": "\\n\\n",
"newline": "\\n",
"pipe": "|",
"semicolon": ";",
"slash": "/",
"space": " ",
"tab": "\\t",
}
func SeparatorFromArg(name string) string {
sep, ok := SEPARATOR_NAMES_TO_VALUES[name]
if !ok {
// "\001" -> control-A, etc.
return lib.UnbackslashStringLiteral(name)
}
return sep
}