From 97aad36ed704976b18f00a9c2ddc4b63cbd8f592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Scha=CC=88fer?= <101886095+PeterSchafer@users.noreply.github.com> Date: Thu, 5 Sep 2024 08:49:52 +0200 Subject: [PATCH] chore: add a sleep to allow attaching the debugger --- cliv2/Makefile | 2 +- cliv2/cmd/cliv2/debug.go | 18 ++++++++++++++++++ cliv2/cmd/cliv2/logheader.go | 2 +- cliv2/cmd/cliv2/main.go | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cliv2/Makefile b/cliv2/Makefile index aa23ff92d7..9fb8cb20d2 100644 --- a/cliv2/Makefile +++ b/cliv2/Makefile @@ -161,7 +161,7 @@ fips: .PHONY: debug debug: - $(eval LDFLAGS := -X github.com/snyk/snyk-ls/application/config.Development=true) + $(eval LDFLAGS := -X github.com/snyk/snyk-ls/application/config.Development=true -X main.buildType=debug) $(eval GCFLAGS := -gcflags="all=-N -l") @echo "$(LOG_PREFIX) DEBUG" diff --git a/cliv2/cmd/cliv2/debug.go b/cliv2/cmd/cliv2/debug.go index d0e6bb7a88..0262a501bc 100644 --- a/cliv2/cmd/cliv2/debug.go +++ b/cliv2/cmd/cliv2/debug.go @@ -12,10 +12,13 @@ import ( "github.com/snyk/go-application-framework/pkg/configuration" "github.com/snyk/go-application-framework/pkg/logging" + "github.com/snyk/go-application-framework/pkg/ui" debug_tools "github.com/snyk/cli/cliv2/internal/debug" ) +var buildType string = "" + func initDebugLogger(config configuration.Configuration) *zerolog.Logger { var consoleWriter = zerolog.ConsoleWriter{ Out: os.Stderr, @@ -42,3 +45,18 @@ func initDebugLogger(config configuration.Configuration) *zerolog.Logger { debugLogger.Log().Msgf("Using log level: %s", loglevel) return &debugLogger } + +func initDebugBuild() { + if strings.EqualFold(buildType, "debug") { + progress := ui.DefaultUi().NewProgressBar() + progress.SetTitle("Pausing execution to attach the debugger!") + waitTimeInSeconds := 10 + + for i := range waitTimeInSeconds { + value := float64(waitTimeInSeconds-i) / float64(waitTimeInSeconds) + progress.UpdateProgress(value) + time.Sleep(1 * time.Second) + } + progress.Clear() + } +} diff --git a/cliv2/cmd/cliv2/logheader.go b/cliv2/cmd/cliv2/logheader.go index f4dc067b4c..91033efb5e 100644 --- a/cliv2/cmd/cliv2/logheader.go +++ b/cliv2/cmd/cliv2/logheader.go @@ -106,7 +106,7 @@ func writeLogHeader(config configuration.Configuration, networkAccess networking fipsEnabled := getFipsStatus(config) - tablePrint("Version", cliv2.GetFullVersion()) + tablePrint("Version", cliv2.GetFullVersion()+" "+buildType) tablePrint("Platform", userAgent) tablePrint("API", config.GetString(configuration.API_URL)) tablePrint("Cache", config.GetString(configuration.CACHE_PATH)) diff --git a/cliv2/cmd/cliv2/main.go b/cliv2/cmd/cliv2/main.go index 97821485cd..def88e3ea8 100644 --- a/cliv2/cmd/cliv2/main.go +++ b/cliv2/cmd/cliv2/main.go @@ -441,6 +441,8 @@ func displayError(err error, userInterface ui.UserInterface, config configuratio } func MainWithErrorCode() int { + initDebugBuild() + startTime := time.Now() var err error rInfo := runtimeinfo.New(runtimeinfo.WithName("snyk-cli"), runtimeinfo.WithVersion(cliv2.GetFullVersion()))