Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: Exit with status 0 when -h is used #87

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- cmd/errtrace: Don't exit with a non-zero status when `-h` is used.

## v0.3.0 - 2023-12-22

This release adds support to the CLI for using Go package patterns like `./...`
Expand Down
4 changes: 4 additions & 0 deletions cmd/errtrace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ package main
import (
"bytes"
"encoding/json"
"errors"
"flag"
"fmt"
"go/ast"
Expand Down Expand Up @@ -184,6 +185,9 @@ func (cmd *mainCmd) Run(args []string) (exitCode int) {

var p mainParams
if err := p.Parse(cmd.Stderr, args); err != nil {
if errors.Is(err, flag.ErrHelp) {
return 0
}
cmd.log.Printf("errtrace: %+v", err)
return 1
}
Expand Down
11 changes: 11 additions & 0 deletions cmd/errtrace/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ import (
"braces.dev/errtrace/internal/diff"
)

func TestErrHelp(t *testing.T) {
exitCode := (&mainCmd{
Stdin: strings.NewReader(""),
Stdout: testWriter{t},
Stderr: testWriter{t},
}).Run([]string{"-h"})
if want := 0; exitCode != want {
t.Errorf("exit code = %d, want %d", exitCode, want)
}
}

// TestGolden runs errtrace on all .go files inside testdata/golden,
// and compares the output to the corresponding .golden file.
// Files must match exactly.
Expand Down
Loading