Improve UI with additional info

This commit is contained in:
abhisek
2025-05-14 19:08:25 +05:30
parent 4dcf7cad0b
commit a9d5dc61a6
5 changed files with 57 additions and 4 deletions
+18
View File
@@ -29,6 +29,8 @@ pnpm add <package-name>
- [Binaries](#binaries)
- [Build from Source](#build-from-source)
- [Usage](#usage)
- [Silent Mode](#silent-mode)
- [Verbose Mode](#verbose-mode)
- [Debugging](#debugging)
- [PMG in Action](#pmg-in-action)
- [Malicious Package Detection](#malicious-package-detection)
@@ -95,6 +97,22 @@ npm install <package-name>
pnpm add <package-name>
```
### Silent Mode
Use the `--silent` flag to run PMG in silent mode:
```bash
pmg --silent npm install <package-name>
```
### Verbose Mode
Use the `--verbose` flag to run PMG in verbose mode:
```bash
pmg --verbose npm install <package-name>
```
### Debugging
Use the `--debug` flag to enable debug mode:
+3
View File
@@ -26,6 +26,9 @@ type PackageVersionAnalysisResult struct {
// Analyser specific analysis ID
AnalysisID string
// Reference URL for the analysis
ReferenceURL string
// The action to take as recommended by the analyzer
Action Action
+5
View File
@@ -55,6 +55,7 @@ func (a *malysisQueryAnalyzer) Analyze(ctx context.Context,
// By default, the analyzer allows the package version
analysisResult := &PackageVersionAnalysisResult{
PackageVersion: packageVersion,
ReferenceURL: malysisReportUrl(res.GetAnalysisId()),
Action: ActionAllow,
AnalysisID: res.GetAnalysisId(),
Summary: res.GetReport().GetInference().GetSummary(),
@@ -73,3 +74,7 @@ func (a *malysisQueryAnalyzer) Analyze(ctx context.Context,
return analysisResult, nil
}
func malysisReportUrl(analysisId string) string {
return fmt.Sprintf("https://platform.safedep.io/community/malysis/%s", analysisId)
}
+14 -3
View File
@@ -59,14 +59,25 @@ func SetStatus(status string) {
func GetConfirmationOnMalware(malwarePackages []*analyzer.PackageVersionAnalysisResult) (bool, error) {
StopSpinner()
fmt.Println(Colors.Red(fmt.Sprintf("🚨 Malicious packages detected: %d", len(malwarePackages))))
fmt.Println()
fmt.Println(Colors.Red(fmt.Sprintf("🚨 Suspicious package(s) detected: %d", len(malwarePackages))))
for _, mp := range malwarePackages {
fmt.Println()
fmt.Println("⚠️ ", Colors.Red(fmt.Sprintf("%s@%s", mp.PackageVersion.GetPackage().GetName(),
mp.PackageVersion.GetVersion())))
fmt.Println(Colors.Yellow(termWidthFormatText(mp.Summary, 60)))
fmt.Println()
if verbosityLevel == VerbosityLevelVerbose {
fmt.Println(Colors.Yellow(termWidthFormatText(mp.Summary, 60)))
if mp.ReferenceURL != "" {
fmt.Println()
fmt.Println(Colors.Yellow(fmt.Sprintf("Reference: %s", mp.ReferenceURL)))
}
fmt.Println()
}
}
fmt.Println()
+17 -1
View File
@@ -7,11 +7,14 @@ import (
"github.com/safedep/dry/log"
"github.com/safedep/pmg/cmd/npm"
"github.com/safedep/pmg/config"
"github.com/safedep/pmg/internal/ui"
"github.com/spf13/cobra"
)
var (
debug bool
silent bool
verbose bool
globalConfig config.Config
)
@@ -26,6 +29,17 @@ func main() {
log.InitZapLogger("pmg", "")
if silent && verbose {
fmt.Println("pmg: --silent and --verbose cannot be used together")
os.Exit(1)
}
if silent {
ui.SetVerbosityLevel(ui.VerbosityLevelSilent)
} else if verbose {
ui.SetVerbosityLevel(ui.VerbosityLevelVerbose)
}
cmd.SetContext(globalConfig.Inject(cmd.Context()))
},
RunE: func(cmd *cobra.Command, args []string) error {
@@ -38,7 +52,9 @@ func main() {
},
}
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "Enable debug logging")
cmd.PersistentFlags().BoolVar(&silent, "silent", false, "Silent mode for invisible experience")
cmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Verbose mode for more information")
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "Enable debug logging (defaults to stdout)")
cmd.PersistentFlags().BoolVar(&globalConfig.Transitive, "transitive", true, "Resolve transitive dependencies")
cmd.PersistentFlags().IntVar(&globalConfig.TransitiveDepth, "transitive-depth", 20,
"Maximum depth of transitive dependencies to resolve")