Default to "cat" verb when none is supplied#2060
Merged
Merged
Conversation
Invocations like 'mlr --j2y' or 'mlr --c2p' previously failed with "no verb supplied", forcing users to type the trailing 'cat' explicitly for pure format conversions. Default the verb to 'cat' in that case. Bare 'mlr' with no flags, no verb, and no files still prints the main usage banner. This handles flag-only invocations (e.g. 'mlr --c2j < input.csv' or 'mlr --c2j --from input.csv'). File names without a preceding verb are still parsed as verb candidates and continue to error if not found; that broader change is out of scope here.
The regtester only substitutes the mlr executable when the cmd
starts with "mlr " (with a trailing space). The bare-mlr usage-banner
test had a cmd of just "mlr", so on CI -- which invokes regtest with
a relative path like 'test/../mlr' -- the test shelled out to a
literal 'mlr' that isn't on PATH and failed with exit 127.
Switch the cmd to ${MLR} (the regtester's explicit substitution
token) so the case runs the right binary in any invocation context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2029.
Summary
Invocations like
mlr --j2yormlr --c2ppreviously failed withno verb supplied. With this change, the verb defaults tocatwhenever it's absent, so pure format conversions can be written as:A bare
mlr(no flags, no verb, no files) still prints the main usage banner.Scope (Option A)
This implements the minimal "Option A" approach: default to
catwhen the parser would otherwise fail with "no verb supplied". File names without a preceding verb (e.g.mlr --c2j input.csv) are still parsed as verb candidates and continue to fail verb lookup; that broader change ("Option B" — fall through to data file when the first non-flag arg isn't a known verb) is intentionally deferred. Users who want a verbless file invocation can use--from:Files changed
pkg/climain/mlrcli_parse.go— synthesize acatverb sequence instead of erroring; keep the usage banner for baremlr.pkg/terminals/help/entry.go— updateMainUsageto show[verb](optional) and document the cat default. This flows through tomlr --help, the man page, and online help.docs/src/reference-verbs.md.in,docs/src/reference-main-overview.md.in,docs/src/keystroke-savers.md.in— note thatcatis the default verb.docs/src/*.md,docs/src/manpage.{md,txt},man/manpage.txt,man/mlr.1.Test plan
test/cases/cli-default-verb-cat/0001..0004: JSON-to-YAML via stdin (issue's example), CSV-to-pprint via stdin, CSV-to-JSON via--from, baremlrstill emits usage with exit 1.make buildmake check— all 4658 regression cases pass (4654 existing + 4 new).make -C docs/src forcebuildandmake -C man— both clean.echo '{"b":22,"c":33,"a":11}' | mlr --j2yproduces YAML output as expected.