mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-04 12:33:04 +00:00
i dont like commits
This commit is contained in:
+23
-72
@@ -1,90 +1,41 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
scorecardCompact bool
|
||||
scorecardDetailed bool
|
||||
scorecardOutput string
|
||||
scorecardPath string
|
||||
scorecardBadgePath string
|
||||
scorecardResetSubjective bool
|
||||
scorecardSkipSlow bool
|
||||
)
|
||||
|
||||
var scorecardCmd = &cobra.Command{
|
||||
Use: "scorecard",
|
||||
Short: "Generate Devour quality scorecards",
|
||||
Long: `Generate beautiful dark-themed scorecards showing code quality metrics.
|
||||
|
||||
Creates both compact and detailed PNG banners with:
|
||||
- Modern dark theme design
|
||||
- Glass morphism effects
|
||||
- Devour brand colors
|
||||
- Professional typography
|
||||
Short: "Generate a scorecard badge via desloppify",
|
||||
Long: `Generate the quality scorecard badge by delegating to desloppify.
|
||||
|
||||
This runs a scan and writes badge output to --badge-path.
|
||||
Examples:
|
||||
devour scorecard # Generate both compact and detailed
|
||||
devour scorecard --compact # Generate only compact banner
|
||||
devour scorecard --detailed # Generate only detailed banner
|
||||
devour scorecard --output custom # Custom output filename`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
generateScorecards()
|
||||
devour scorecard
|
||||
devour scorecard --path . --badge-path scorecard.png
|
||||
devour scorecard --reset-subjective`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
forward := []string{"scan", "--path", scorecardPath, "--badge-path", scorecardBadgePath}
|
||||
if scorecardResetSubjective {
|
||||
forward = append(forward, "--reset-subjective")
|
||||
}
|
||||
if scorecardSkipSlow {
|
||||
forward = append(forward, "--skip-slow")
|
||||
}
|
||||
return runDesloppifyFromCommand(cmd, forward, true)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
scorecardCmd.Flags().BoolVar(&scorecardCompact, "compact", false, "Generate compact banner only")
|
||||
scorecardCmd.Flags().BoolVar(&scorecardDetailed, "detailed", false, "Generate detailed banner only")
|
||||
scorecardCmd.Flags().StringVarP(&scorecardOutput, "output", "o", "lighthouse_scorecard", "Output filename prefix")
|
||||
}
|
||||
|
||||
func generateScorecards() {
|
||||
// Get the current working directory (project root)
|
||||
workingDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting working directory: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Path to the Python script relative to working directory
|
||||
pythonScriptPath := filepath.Join(workingDir, "cmd", "banner_generator", "main.py")
|
||||
|
||||
// Check if Python script exists
|
||||
if _, err := os.Stat(pythonScriptPath); os.IsNotExist(err) {
|
||||
fmt.Fprintf(os.Stderr, "Error: Python scorecard generator not found at %s\n", pythonScriptPath)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Build Python command arguments
|
||||
args := []string{pythonScriptPath}
|
||||
|
||||
if scorecardCompact {
|
||||
args = append(args, "--compact")
|
||||
} else if scorecardDetailed {
|
||||
args = append(args, "--detailed")
|
||||
}
|
||||
|
||||
if scorecardOutput != "lighthouse_scorecard" {
|
||||
args = append(args, "--output", scorecardOutput)
|
||||
}
|
||||
|
||||
// Execute Python script
|
||||
fmt.Println("🎨 Generating Devour Scorecards...")
|
||||
fmt.Printf("📂 Using generator: %s\n", pythonScriptPath)
|
||||
|
||||
cmd := exec.Command("python3", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Dir = workingDir
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error generating scorecards: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("✅ Scorecard generation complete!")
|
||||
scorecardCmd.Flags().StringVar(&scorecardPath, "path", ".", "Path to scan")
|
||||
scorecardCmd.Flags().StringVar(&scorecardBadgePath, "badge-path", "scorecard.png", "Badge output path")
|
||||
scorecardCmd.Flags().BoolVar(&scorecardResetSubjective, "reset-subjective", false, "Reset subjective scores before scan")
|
||||
scorecardCmd.Flags().BoolVar(&scorecardSkipSlow, "skip-slow", false, "Skip slow detectors")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user