miller/pkg/cli/errors.go
John Kerl be19a21280
Remove os.Exit callsites below the entrypoint: phase 2 (#2202)
* Remove os.Exit callsites below the entrypoint: phase 2 (plans/exit.md)

Phase 2 of plans/exit.md: the FlagParser signature change.

- FlagParser gains an error return; all 259 inline parser closures in
  option_parse.go and NoOpParse1 updated (mechanical rewrite, compiler-checked).
- FlagTable.Parse returns (bool, error); its nine callers (climain passes one
  and two, .mlrrc line handling, verb-local flag parsing in tee/join/put/
  filter/split, and the repl/script terminals) propagate the error instead of
  letting parsers kill the process.
- cli.CheckArgCount returns its missing-argument message as an error rather
  than printing and exiting; new cli.FlagErrorf (counterpart of VerbErrorf)
  carries user-facing main-flag messages.
- The 14 print-and-exit sites inside parser closures become returned errors;
  --list-color-codes/--list-color-names return ExitRequest{0} after printing.
- The repl and script terminals translate ExitRequest into their int return
  codes, so 'mlr repl --list-color-codes' still exits 0.
- pkg/cli is now os.Exit-free; stale comments about exiting parsers updated
  (the completion introspection accessors remain, since parsers mutate the
  options struct).

Stderr messages and exit codes are byte-identical, including the two-line
missing-argument and --seed messages and the trailing-period forms pinned by
test/cases/cli-mfrom/0003.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Merge main (recutils #2201); convert its three new parser closures

Same mechanical rewrite as the rest of phase 2: error return signature plus
final 'return nil' on --irecutils/--orecutils/--recutils.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 14:09:57 -04:00

24 lines
864 B
Go

package cli
import (
"errors"
"fmt"
)
// ErrHelpRequested is returned by verb ParseCLIFunc when -h or --help is used.
// The caller (CLI layer) should exit with code 0 after the verb has printed its
// usage to stdout.
var ErrHelpRequested = errors.New("help requested")
// ErrUsagePrinted is returned by verb ParseCLIFunc when validation fails. The
// verb has already printed its usage to stderr. The caller should exit 1
// without printing the error again.
var ErrUsagePrinted = errors.New("usage printed")
// FlagErrorf is for user-facing main-flag errors (the counterpart of
// VerbErrorf for verb flags). The message is complete prose, ready for the
// entrypoint layer to print as-is: it should carry the "mlr: " prefix and may
// span multiple lines.
func FlagErrorf(format string, args ...interface{}) error {
return fmt.Errorf(format, args...)
}