Artifact ecd2eff17c5f793f5a5c51fbe9ff0610094624c3df3a23a2a9e8ee3355b3bc55:
- File
cmd/libfossil/main.go
— part of check-in
[8fdb632783]
at
2026-10-19 22:55:46
on branch feat/cli-snapshot
— fix(cli): print usage errors on stderr and pin their exit status 80
The documented status was right for the binary; go run turns it into 1. Usage text went to stdout, so an embedder reading stdout saw it on a failure. The doc now says which status a measurement under go run shows, and a test pins 80 for an unknown flag, a missing flag or argument and an unknown subcommand. (user: [email protected], size: 1298) [annotate] [blame] [check-ins using] [more...]
package main import ( "errors" "fmt" "os" "github.com/alecthomas/kong" "github.com/danmestas/go-libfossil/cli" ) // CLI is the top-level command structure. // // Version is deliberately a subcommand only, not also a global --version // flag: `repo extract` already has its own --version flag (the source // version to extract from), and kong's global flags are visible in every // subcommand's context, so a root-level --version would collide with it. // Renaming that existing, unrelated flag to make room isn't part of this // change. type CLI struct { cli.Globals Repo cli.RepoCmd `cmd:"" help:"Repository operations"` Version cli.VersionCmd `cmd:"" help:"Print version information"` } func main() { var c CLI parser := kong.Must(&c, kong.Name("libfossil"), kong.Description("Fossil-compatible repository tool (pure Go)"), kong.UsageOnError(), ) ctx, err := parser.Parse(os.Args[1:]) if err != nil { // A usage error prints the usage with the error, on stderr, and // exits 80: stdout carries only a command's output. parser.Stdout = parser.Stderr parser.FatalIfErrorf(err) } err = ctx.Run(&c.Globals) var exit *cli.ExitError if errors.As(err, &exit) { fmt.Fprintf(os.Stderr, "libfossil: %v\n", exit) os.Exit(exit.Code) } ctx.FatalIfErrorf(err) }