Skip to content

Commit

Permalink
fix: doctor command
Browse files Browse the repository at this point in the history
  • Loading branch information
mkloubert committed Jan 3, 2025
1 parent e0e7144 commit 03a8108
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log (go-package-manager)

## 0.29.6
## 0.29.7

- feat: self-update by executing `gpm update --self`
- chore: improve (self-)update scripts
Expand Down
24 changes: 14 additions & 10 deletions commands/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ func Init_Doctor_Command(parentCmd *cobra.Command, app *types.AppContext) {

fmt.Println()

// cleanups and extract direct items
directItems := make([]GoModFileRequireItem, 0)
// cleanups and extract items as references
allItems := make([]*GoModFileRequireItem, 0)
directItems := make([]*GoModFileRequireItem, 0)
for _, item := range goMod.Require {
item.Path = strings.TrimSpace(strings.ToLower(item.Path))
item.Version = strings.TrimSpace(item.Version)
refItem := &item

if item.Indirect == nil || !*item.Indirect {
directItems = append(directItems, item)
refItem.Path = strings.TrimSpace(strings.ToLower(refItem.Path))
refItem.Version = strings.TrimSpace(refItem.Version)

allItems = append(allItems, refItem)
if refItem.Indirect == nil || !*refItem.Indirect {
directItems = append(directItems, refItem)
}
}

Expand Down Expand Up @@ -199,10 +203,10 @@ func Init_Doctor_Command(parentCmd *cobra.Command, app *types.AppContext) {
fmt.Println()

fmt.Println("Checking for unsed dependencies ...")
for i, item := range goMod.Require {
for i, item := range allItems {
s := spinner.New(spinner.CharSets[24], 100*time.Millisecond)
s.Prefix = "\t["
s.Suffix = fmt.Sprintf("] Checking '%s' (%v/%v) ...", item.Path, i+1, len(goMod.Require))
s.Suffix = fmt.Sprintf("] Checking '%s' (%v/%v) ...", item.Path, i+1, len(allItems))
s.Start()

p := exec.Command("go", "mod", "why", "-m", item.Path)
Expand All @@ -228,10 +232,10 @@ func Init_Doctor_Command(parentCmd *cobra.Command, app *types.AppContext) {
fmt.Println()

fmt.Println("Checking all dependencies for security issues ...")
for i, item := range goMod.Require {
for i, item := range allItems {
s := spinner.New(spinner.CharSets[24], 100*time.Millisecond)
s.Prefix = "\t["
s.Suffix = fmt.Sprintf("] Checking '%s' (%v/%v) ...", item.Path, i+1, len(goMod.Require))
s.Suffix = fmt.Sprintf("] Checking '%s' (%v/%v) ...", item.Path, i+1, len(allItems))
s.Start()

url := "https://api.osv.dev/v1/query"
Expand Down

0 comments on commit 03a8108

Please sign in to comment.