mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
Enhance pmg outputs by adding colors and removing markdown notions
This commit is contained in:
@@ -5,6 +5,7 @@ go 1.24.1
|
|||||||
require (
|
require (
|
||||||
buf.build/gen/go/safedep/api/grpc/go v1.5.1-20250418165058-162f6b0cc319.2
|
buf.build/gen/go/safedep/api/grpc/go v1.5.1-20250418165058-162f6b0cc319.2
|
||||||
buf.build/gen/go/safedep/api/protocolbuffers/go v1.36.6-20250418165058-162f6b0cc319.1
|
buf.build/gen/go/safedep/api/protocolbuffers/go v1.36.6-20250418165058-162f6b0cc319.1
|
||||||
|
github.com/fatih/color v1.18.0
|
||||||
github.com/jedib0t/go-pretty/v6 v6.6.7
|
github.com/jedib0t/go-pretty/v6 v6.6.7
|
||||||
github.com/safedep/dry v0.0.0-20250410092643-c7079e2f9442
|
github.com/safedep/dry v0.0.0-20250410092643-c7079e2f9442
|
||||||
github.com/safedep/vet v1.10.1
|
github.com/safedep/vet v1.10.1
|
||||||
|
|||||||
@@ -10,14 +10,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ConfirmInstallation(maliciousPkgs map[string]string) bool {
|
func ConfirmInstallation(maliciousPkgs map[string]string) bool {
|
||||||
fmt.Printf("\nWARNING: %d potentially malicious packages detected!\n", len(maliciousPkgs))
|
colors := NewTerminalColors()
|
||||||
fmt.Println("The following packages have been flagged:")
|
|
||||||
|
fmt.Printf("\n%s\n", colors.Red("⚠️ WARNING: %d potentially malicious packages detected!", len(maliciousPkgs)))
|
||||||
|
fmt.Println(colors.Yellow("The following packages have been flagged:"))
|
||||||
|
|
||||||
for name, reason := range maliciousPkgs {
|
for name, reason := range maliciousPkgs {
|
||||||
fmt.Printf("- %s: %s\n", name, reason)
|
fmt.Printf("%s %s: %s\n",
|
||||||
|
colors.Cyan("•"), // bullet point
|
||||||
|
colors.Yellow(name),
|
||||||
|
removeMarkdown(reason),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("\nDo you want to continue with installation? (y/N): ")
|
fmt.Print("\n", colors.Green("Do you want to continue with installation? (y/N): "))
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
response, err := reader.ReadString('\n')
|
response, err := reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "github.com/fatih/color"
|
||||||
|
|
||||||
|
type TerminalColors struct {
|
||||||
|
Red func(format string, a ...interface{}) string
|
||||||
|
Yellow func(format string, a ...interface{}) string
|
||||||
|
Cyan func(format string, a ...interface{}) string
|
||||||
|
Green func(format string, a ...interface{}) string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTerminalColors initializes and returns TerminalColors
|
||||||
|
func NewTerminalColors() *TerminalColors {
|
||||||
|
return &TerminalColors{
|
||||||
|
Red: color.New(color.FgRed, color.Bold).SprintfFunc(),
|
||||||
|
Yellow: color.New(color.FgYellow).SprintfFunc(),
|
||||||
|
Cyan: color.New(color.FgCyan).SprintfFunc(),
|
||||||
|
Green: color.New(color.FgGreen).SprintfFunc(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -76,3 +76,13 @@ func IsInstallCommand(pkgManager, cmd string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeMarkdown(text string) string {
|
||||||
|
// Remove bold asterisks
|
||||||
|
text = strings.ReplaceAll(text, "**", "")
|
||||||
|
// Remove italic asterisks
|
||||||
|
text = strings.ReplaceAll(text, "*", "")
|
||||||
|
// Remove backticks
|
||||||
|
text = strings.ReplaceAll(text, "`", "")
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
"github.com/safedep/dry/log"
|
"github.com/safedep/dry/log"
|
||||||
"github.com/safedep/pmg/internal/ui"
|
"github.com/safedep/pmg/internal/ui"
|
||||||
"github.com/safedep/pmg/pkg/analyser"
|
"github.com/safedep/pmg/pkg/analyser"
|
||||||
@@ -133,7 +134,8 @@ func (pmw *PackageManagerWrapper) analyzeDependencies(ctx context.Context, deps
|
|||||||
log.Infof("Installation canceled due to security concerns")
|
log.Infof("Installation canceled due to security concerns")
|
||||||
return fmt.Errorf("installation canceled")
|
return fmt.Errorf("installation canceled")
|
||||||
}
|
}
|
||||||
log.Warnf("Continuing installation despite security warnings...")
|
yellow := color.New(color.FgYellow, color.Bold).SprintfFunc()
|
||||||
|
log.Warnf(yellow("Continuing installation despite security warnings..."))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user