mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-18 00:45:47 +00:00
* initial attempt
* fix bash
* fix zsh
* Add shell-completion docs page
Documents the new 'mlr completion {bash,zsh}' feature: the then-chain
context model, install instructions for bash and zsh (including the macOS
bash-3.2 'eval' caveat and zsh compinit self-init), and examples of
context-aware completion. Added to the nav under "Miller in more detail".
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Add enum value completion for format and separator flags
Completes the argument value for arg-taking main flags whose values are a
known set: file-format names for -i/-o/--io, separator aliases for
--ifs/--ofs/--ips/etc., and regex-separator aliases for --ifs-regex/--ips-regex.
Other arg-taking flags continue to fall back to filename completion.
Candidate sets come from new cli getters (GetFileFormatNames,
GetSeparatorAliasNames, GetSeparatorRegexAliasNames) that read the same maps
Miller uses at runtime, so there is no separate list to keep in sync. The
command-line walk now records which flag a value position belongs to.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Include format-conversion keystroke-savers in bare-dash completion
Reverts the suppression of --c2j/--x2y-style flags from 'mlr -<TAB>'. The full
set of main flags (297) is now offered, matching what is valid on the command
line. GetFlagNames no longer takes an includeSuppressed argument.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Complete terminal subcommands and top-level help/version flags
'mlr <TAB>' now offers subcommand names (help, version, repl, regtest, script,
completion, terminal-list) alongside verb names, and 'mlr -<TAB>' offers the
top-level terminal flags (-h, --help, --version, --bare-version, and the help
shorthands -g/-l/-L/-f/-F/-k/-K). Subcommand names are offered only as the
first non-flag token, where they are valid.
To let the completion engine know these names without an import cycle
(pkg/terminals imports pkg/terminals/completion), the canonical terminal names
and version-flag spellings are factored into a new leaf package
pkg/terminals/registry, imported by pkg/terminals, pkg/climain, and completion.
The help-flag spellings come from a new help.GetTerminalFlagNames derived from
the existing shorthand table, so nothing drifts.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* Complete 'mlr help' topics and topic arguments
'mlr help <TAB>' now completes help topics (flags, verb, function, keyword,
list-verbs, ...), and topics that take a name argument complete it too:
'mlr help verb <TAB>' -> verb names, 'mlr help function <TAB>' -> function
names, 'mlr help keyword <TAB>' -> keyword names, 'mlr help flag <TAB>' ->
flag names. 'mlr completion <TAB>' completes bash/zsh.
A terminal subcommand consumes the rest of the command line, so the walk now
returns a ctxTerminalArgs context carrying the terminal name and the words
typed after it. New getters supply the candidate names without drift:
help.GetTopicNames, help.GetFunctionNames/GetKeywordNames (wrapping new
cst.BuiltinFunctionManager.GetBuiltinFunctionNames and cst.GetKeywordNames).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* docs-neaten
* Move flag-value-candidate logic into pkg/cli; fix verb-flag collision
The mapping of which flags take a format/separator/regex-separator argument is
flag metadata, so it now lives with the flags in pkg/cli as
cli.FlagValueCandidates, alongside the existing GetFileFormatNames /
GetSeparatorAliasNames getters, replacing the maps that were in
pkg/terminals/completion/value_completion.go (now removed).
This also fixes a bug: value completion now applies only to main flags, not to
identically-spelled verb flags. Previously 'mlr uniq -o <TAB>' offered file
formats because uniq's -o (an output field name) collided with the main -o
format flag; it now correctly falls back to filename completion.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
169 lines
4.2 KiB
Go
169 lines
4.2 KiB
Go
package cli
|
|
|
|
import "github.com/johnkerl/miller/v6/pkg/lib"
|
|
|
|
const COLON = ":"
|
|
const COMMA = ","
|
|
const CR = "\\r"
|
|
const CRCR = "\\r\\r"
|
|
const CRLF = "\\r\\n"
|
|
const CRLFCRLF = "\\r\\n\\r\\n"
|
|
const EQUALS = "="
|
|
const LF = "\\n"
|
|
const LFLF = "\\n\\n"
|
|
const NEWLINE = "\\n"
|
|
const PIPE = "|"
|
|
const SEMICOLON = ";"
|
|
const SLASH = "/"
|
|
const SPACE = " "
|
|
const TAB = "\\t"
|
|
|
|
const SPACES_REGEX = "( )+"
|
|
const TABS_REGEX = "(\\t)+"
|
|
const WHITESPACE_REGEX = "([ \\t])+"
|
|
|
|
const ASCII_ESC = "\\x1b"
|
|
const ASCII_ETX = "\\x03"
|
|
const ASCII_FS = "\\x1c"
|
|
const ASCII_GS = "\\x1d"
|
|
const ASCII_NULL = "\\x00"
|
|
const ASCII_RS = "\\x1e"
|
|
const ASCII_SOH = "\\x01"
|
|
const ASCII_STX = "\\x02"
|
|
const ASCII_US = "\\x1f"
|
|
|
|
const ASV_FS = "\\x1f"
|
|
const ASV_RS = "\\x1e"
|
|
const USV_FS = "\\xe2\\x90\\x9f"
|
|
const USV_RS = "\\xe2\\x90\\x9e"
|
|
|
|
const ASV_FS_FOR_HELP = "\\x1f"
|
|
const ASV_RS_FOR_HELP = "\\x1e"
|
|
const USV_FS_FOR_HELP = "U+241F (UTF-8 \\xe2\\x90\\x9f)"
|
|
const USV_RS_FOR_HELP = "U+241E (UTF-8 \\xe2\\x90\\x9e)"
|
|
|
|
const DEFAULT_JSON_FLATTEN_SEPARATOR = "."
|
|
|
|
var SEPARATOR_NAMES_TO_VALUES = map[string]string{
|
|
"ascii_esc": ASCII_ESC,
|
|
"ascii_etx": ASCII_ETX,
|
|
"ascii_fs": ASCII_FS,
|
|
"ascii_gs": ASCII_GS,
|
|
"ascii_null": ASCII_NULL,
|
|
"ascii_rs": ASCII_RS,
|
|
"ascii_soh": ASCII_SOH,
|
|
"ascii_stx": ASCII_STX,
|
|
"ascii_us": ASCII_US,
|
|
"asv_fs": ASV_FS,
|
|
"asv_rs": ASV_RS,
|
|
"colon": COLON,
|
|
"comma": COMMA,
|
|
"cr": CR,
|
|
"crcr": CRCR,
|
|
"crlf": CRLF,
|
|
"crlfcrlf": CRLFCRLF,
|
|
"equals": EQUALS,
|
|
"lf": LF,
|
|
"lflf": LFLF,
|
|
"newline": NEWLINE,
|
|
"pipe": PIPE,
|
|
"semicolon": SEMICOLON,
|
|
"slash": SLASH,
|
|
"space": SPACE,
|
|
"tab": TAB,
|
|
"usv_fs": USV_FS,
|
|
"usv_rs": USV_RS,
|
|
}
|
|
|
|
var SEPARATOR_REGEX_NAMES_TO_VALUES = map[string]string{
|
|
"spaces": SPACES_REGEX,
|
|
"tabs": TABS_REGEX,
|
|
"whitespace": WHITESPACE_REGEX,
|
|
}
|
|
|
|
// E.g. if IFS isn't specified, it's space for NIDX and comma for DKVP, etc.
|
|
|
|
var defaultFSes = map[string]string{
|
|
"gen": ",",
|
|
"csv": ",",
|
|
"csvlite": ",",
|
|
"dkvp": ",",
|
|
"dkvpx": ",",
|
|
"json": "N/A", // not alterable; not parameterizable in JSON format
|
|
"yaml": "N/A",
|
|
"dcf": "N/A",
|
|
"nidx": " ",
|
|
"markdown": " ",
|
|
"pprint": " ",
|
|
"tsv": "\t",
|
|
"xtab": "\n", // todo: windows-dependent ...
|
|
}
|
|
|
|
// GetFileFormatNames returns the canonical file-format names (csv, json, tsv,
|
|
// ...), sorted, for shell-completion of the -i/-o/--io flags. These are the
|
|
// keys of defaultFSes, which is the same set the reader/writer factories
|
|
// dispatch on.
|
|
func GetFileFormatNames() []string {
|
|
return lib.GetArrayKeysSorted(defaultFSes)
|
|
}
|
|
|
|
// GetSeparatorAliasNames returns the named separator aliases (comma, tab,
|
|
// pipe, ...), sorted, for shell-completion of separator flags like --ifs.
|
|
func GetSeparatorAliasNames() []string {
|
|
return lib.GetArrayKeysSorted(SEPARATOR_NAMES_TO_VALUES)
|
|
}
|
|
|
|
// GetSeparatorRegexAliasNames returns the named regex separator aliases
|
|
// (spaces, tabs, whitespace), sorted, for shell-completion of the
|
|
// --ifs-regex/--ips-regex flags.
|
|
func GetSeparatorRegexAliasNames() []string {
|
|
return lib.GetArrayKeysSorted(SEPARATOR_REGEX_NAMES_TO_VALUES)
|
|
}
|
|
|
|
var defaultPSes = map[string]string{
|
|
"gen": "N/A",
|
|
"csv": "N/A",
|
|
"csvlite": "N/A",
|
|
"dkvp": "=",
|
|
"dkvpx": "=",
|
|
"json": "N/A", // not alterable; not parameterizable in JSON format
|
|
"yaml": "N/A",
|
|
"dcf": "N/A",
|
|
"markdown": "N/A",
|
|
"nidx": "N/A",
|
|
"pprint": "N/A",
|
|
"tsv": "N/A",
|
|
"xtab": " ",
|
|
}
|
|
|
|
var defaultRSes = map[string]string{
|
|
"gen": "\n",
|
|
"csv": "\n",
|
|
"csvlite": "\n",
|
|
"dkvp": "\n",
|
|
"dkvpx": "\n",
|
|
"json": "N/A", // not alterable; not parameterizable in JSON format
|
|
"yaml": "N/A",
|
|
"dcf": "N/A",
|
|
"markdown": "\n",
|
|
"nidx": "\n",
|
|
"pprint": "\n",
|
|
"tsv": "\n",
|
|
"xtab": "\n\n", // todo: maybe jettison the idea of this being alterable
|
|
}
|
|
|
|
var defaultAllowRepeatIFSes = map[string]bool{
|
|
"gen": false,
|
|
"csv": false,
|
|
"csvlite": false,
|
|
"dkvp": false,
|
|
"dkvpx": false,
|
|
"json": false,
|
|
"yaml": false,
|
|
"dcf": false,
|
|
"markdown": false,
|
|
"nidx": false,
|
|
"pprint": true,
|
|
"tsv": false,
|
|
"xtab": false,
|
|
}
|