From de9236ce9f4b88c0fc8e5aa832150f2c428284d7 Mon Sep 17 00:00:00 2001 From: Junjie Gao Date: Mon, 3 Mar 2025 06:22:13 +0000 Subject: [PATCH] fix: notify context concelation when SIGINT Signed-off-by: Junjie Gao --- cmd/notation/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/notation/main.go b/cmd/notation/main.go index 7f33a1202..c78c70324 100644 --- a/cmd/notation/main.go +++ b/cmd/notation/main.go @@ -14,7 +14,9 @@ package main import ( + "context" "os" + "os/signal" "github.com/notaryproject/notation-go/dir" "github.com/notaryproject/notation/cmd/notation/blob" @@ -65,7 +67,10 @@ func main() { versionCommand(), inspectCommand(nil), ) - if err := cmd.Execute(); err != nil { + + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer cancel() + if err := cmd.ExecuteContext(ctx); err != nil { os.Exit(1) } }