Skip to content

Commit

Permalink
chore: fitactivity simplify notify signal
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari committed Sep 13, 2024
1 parent 68a45e7 commit fc164c4
Showing 1 changed file with 4 additions and 11 deletions.
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

0 comments on commit fc164c4

Please sign in to comment.