Skip to content

Default to "cat" verb when none is supplied#2060

Merged
johnkerl merged 2 commits into
mainfrom
johnkerl/2029
May 17, 2026
Merged

Default to "cat" verb when none is supplied#2060
johnkerl merged 2 commits into
mainfrom
johnkerl/2029

Conversation

@johnkerl
Copy link
Copy Markdown
Owner

Fixes #2029.

Summary

Invocations like mlr --j2y or mlr --c2p previously failed with no verb supplied. With this change, the verb defaults to cat whenever it's absent, so pure format conversions can be written as:

$ echo '{"b":22, "c":33, "a":11}' | mlr --j2y
b: 22
c: 33
a: 11

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 cat when 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:

mlr --c2j --from input.csv

Files changed

  • pkg/climain/mlrcli_parse.go — synthesize a cat verb sequence instead of erroring; keep the usage banner for bare mlr.
  • pkg/terminals/help/entry.go — update MainUsage to show [verb] (optional) and document the cat default. This flows through to mlr --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 that cat is the default verb.
  • Regenerated: docs/src/*.md, docs/src/manpage.{md,txt}, man/manpage.txt, man/mlr.1.

Test plan

  • Added regression cases 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, bare mlr still emits usage with exit 1.
  • make build
  • make check — all 4658 regression cases pass (4654 existing + 4 new).
  • make -C docs/src forcebuild and make -C man — both clean.
  • Verified echo '{"b":22,"c":33,"a":11}' | mlr --j2y produces YAML output as expected.

johnkerl added 2 commits May 17, 2026 12:00
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.
@johnkerl johnkerl merged commit 86c8097 into main May 17, 2026
7 checks passed
@johnkerl johnkerl deleted the johnkerl/2029 branch May 17, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cat should be "default" verb

1 participant