Skip to content

Commit

Permalink
pin/unpin error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
snwzd committed Nov 14, 2023
1 parent 47781e6 commit 61de57b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions cmd/pin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmd

import (
"fmt"
"strings"

"github.com/apex/log"
"github.com/marcosnils/bin/pkg/config"
"github.com/spf13/cobra"
)
Expand All @@ -21,9 +25,13 @@ func newPinCmd() *pinCmd {
RunE: func(cmd *cobra.Command, args []string) error {
cfg := config.Get()

for _, b := range cfg.Bins {
for _, p := range args {
for _, p := range args {
found := false

for _, b := range cfg.Bins {
if b.RemoteName == p {
found = true

bin, err := getBinPath(p)
if err != nil {
return err
Expand All @@ -36,11 +44,14 @@ func newPinCmd() *pinCmd {
return err
}
}
}

// TODO return error for unmatched ones
if !found {
return fmt.Errorf("Binary \"%s\" not found", p)
}
}

log.Infof("Pinned " + strings.Join(args, ", "))
return nil
},
}
Expand Down
17 changes: 14 additions & 3 deletions cmd/unpin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmd

import (
"fmt"
"strings"

"github.com/apex/log"
"github.com/marcosnils/bin/pkg/config"
"github.com/spf13/cobra"
)
Expand All @@ -21,9 +25,13 @@ func newUnpinCmd() *unpinCmd {
RunE: func(cmd *cobra.Command, args []string) error {
cfg := config.Get()

for _, b := range cfg.Bins {
for _, p := range args {
for _, p := range args {
found := false

for _, b := range cfg.Bins {
if b.RemoteName == p {
found = true

bin, err := getBinPath(p)
if err != nil {
return err
Expand All @@ -36,11 +44,14 @@ func newUnpinCmd() *unpinCmd {
return err
}
}
}

// TODO return error for unmatched ones
if !found {
return fmt.Errorf("Binary \"%s\" not found", p)
}
}

log.Infof("Unpinned " + strings.Join(args, ", "))
return nil
},
}
Expand Down

0 comments on commit 61de57b

Please sign in to comment.