We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5d1eb81 commit 77d45beCopy full SHA for 77d45be
1 file changed
cmd/root.go
@@ -5,6 +5,8 @@ import (
5
"fmt"
6
"log"
7
"os"
8
+ "os/signal"
9
+ "syscall"
10
11
"github.com/spf13/cobra"
12
"github.com/spf13/viper"
@@ -33,7 +35,11 @@ func SetVersionInfo(version string) {
33
35
// Execute adds all child commands to the root command and sets flags appropriately.
34
36
// This is called by main.main(). It only needs to happen once to the rootCmd.
37
func Execute() {
- if err := rootCmd.ExecuteContext(context.Background()); err != nil {
38
+ // Create a context that is canceled on interrupt signals (Ctrl+C, SIGTERM)
39
+ ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
40
+ defer stop()
41
+
42
+ if err := rootCmd.ExecuteContext(ctx); err != nil {
43
fmt.Fprintln(os.Stderr, err)
44
os.Exit(1)
45
}
0 commit comments