diff --git a/internal/cli/root.go b/internal/cli/root.go index edd5d073c..c8ba573ee 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "os/signal" "github.com/auth0/auth0-cli/internal/ansi" "github.com/auth0/auth0-cli/internal/buildinfo" @@ -119,7 +120,7 @@ func Execute() { // for most of the architectures there's no requirements: ansi.InitConsole() - if err := rootCmd.ExecuteContext(context.TODO()); err != nil { + if err := rootCmd.ExecuteContext(contextWithSignal(os.Interrupt)); err != nil { cli.renderer.Heading("error") cli.renderer.Errorf(err.Error()) @@ -127,3 +128,18 @@ func Execute() { os.Exit(1) } } + +func contextWithSignal(sigs ...os.Signal) context.Context { + ctx, cancel := context.WithCancel(context.Background()) + + ch := make(chan os.Signal, 1) + signal.Notify(ch, sigs...) + + go func() { + <-ch + defer cancel() + os.Exit(0) + }() + + return ctx +} diff --git a/internal/cli/template.go b/internal/cli/template.go index d7175637b..9b8eeabb3 100644 --- a/internal/cli/template.go +++ b/internal/cli/template.go @@ -183,7 +183,7 @@ func (cli *cli) obtainCustomTemplateData(ctx context.Context) (*branding.Templat g.Go(func() error { var err error - clients, err = cli.api.Client.List(management.ExcludeFields(clientExcludedList...)) + clients, err = cli.api.Client.List(management.Context(ctx), management.ExcludeFields(clientExcludedList...)) return err })