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

chore: fitactivity simplify notify signal #429

Merged
merged 1 commit into from
Sep 13, 2024
Merged
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
15 changes: 4 additions & 11 deletions cmd/fitactivity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,9 @@ Flags:
`

func main() {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)

go func() {
sig := <-quit
cancel()
fmt.Printf(" %v ", sig)
}()

fs := flag.NewFlagSet("main", flag.ExitOnError)
fs.Usage = func() { fmt.Fprint(os.Stderr, mainUsage) }

Expand Down Expand Up @@ -138,8 +129,10 @@ func printerror(fs *flag.FlagSet, command string, err error) {
fs.Usage()
} else if errors.Is(err, errPrintUsageAndExit) {
fs.Usage()
} else if errors.Is(err, context.Canceled) {
fmt.Fprintf(os.Stderr, "~ %s: %v\n", command, err)
} else {
fmt.Fprintf(os.Stderr, "~ %s: return with error: %v\n", command, err)
fmt.Fprintf(os.Stderr, "~ %s: error: %v\n", command, err)
}
os.Exit(1)
}
Expand Down