Skip to content

Commit

Permalink
Merge pull request #5469 from snyk/chore/improve_local_debugging
Browse files Browse the repository at this point in the history
chore: add a sleep to allow attaching the debugger
  • Loading branch information
PeterSchafer authored Sep 5, 2024
2 parents 2dabad7 + 97aad36 commit 9083ee1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cliv2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
18 changes: 18 additions & 0 deletions cliv2/cmd/cliv2/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}
}
2 changes: 1 addition & 1 deletion cliv2/cmd/cliv2/logheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 9083ee1

Please sign in to comment.