Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"sort"
"strings"
"time"

"github.com/getplumber/plumber/configuration"
"github.com/getplumber/plumber/control"
Expand Down Expand Up @@ -218,10 +219,19 @@ func runAnalyze(cmd *cobra.Command, args []string) error {
conf.LogLevel = logrus.DebugLevel
}

// Run analysis
// Run analysis with spinner
fmt.Fprintf(os.Stderr, "Analyzing project: %s on %s\n", projectPath, cleanGitlabURL)

result, err := control.RunAnalysis(conf)
var result *control.AnalysisResult

// Start spinner in verbose mode (when user wants to see progress)
if verbose {
stopSpinner := startSpinner("Analyzing")
result, err = control.RunAnalysis(conf)
stopSpinner()
} else {
result, err = control.RunAnalysis(conf)
}
if err != nil {
return fmt.Errorf("analysis failed: %w", err)
}
Expand Down Expand Up @@ -1086,3 +1096,34 @@ func printComplianceTable(controls []controlSummary, overallCompliance, threshol
strings.Repeat("═", statusWidth),
colorReset)
}

// startSpinner displays a spinner while the analysis is running
// Returns a stop function that should be called when done
func startSpinner(message string) func() {
stop := make(chan bool)
done := make(chan bool)

go func() {
spinner := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
i := 0

for {
select {
case <-stop:
done <- true
return
default:
fmt.Fprintf(os.Stderr, "\r%s %s... ", spinner[i%len(spinner)], message)
i++
time.Sleep(100 * time.Millisecond)
}
}
}()

return func() {
stop <- true
<-done
// Clear the spinner line
fmt.Fprintf(os.Stderr, "\r")
}
}