mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-17 16:38:54 +00:00
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>
This commit is contained in:
parent
b7804e0791
commit
be19a21280
12 changed files with 770 additions and 385 deletions
|
|
@ -20,12 +20,14 @@
|
|||
package repl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/johnkerl/miller/v6/pkg/cli"
|
||||
"github.com/johnkerl/miller/v6/pkg/lib"
|
||||
)
|
||||
|
||||
func replUsage(verbName string, o *os.File, exitCode int) {
|
||||
|
|
@ -140,7 +142,15 @@ func ReplMain(args []string) int {
|
|||
argi += 1
|
||||
}
|
||||
|
||||
} else if cli.FLAG_TABLE.Parse(args, argc, &argi, options) {
|
||||
} else if handled, flagErr := cli.FLAG_TABLE.Parse(args, argc, &argi, options); flagErr != nil {
|
||||
var exitRequest *lib.ExitRequest
|
||||
if errors.As(flagErr, &exitRequest) {
|
||||
return exitRequest.Code
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "%v\n", flagErr)
|
||||
return 1
|
||||
|
||||
} else if handled {
|
||||
|
||||
} else {
|
||||
replUsage(replName, os.Stderr, 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue