diff --git a/cmd/pin.go b/cmd/pin.go index 5a5b67d..2c7cff1 100644 --- a/cmd/pin.go +++ b/cmd/pin.go @@ -1,6 +1,10 @@ package cmd import ( + "fmt" + "strings" + + "github.com/apex/log" "github.com/marcosnils/bin/pkg/config" "github.com/spf13/cobra" ) @@ -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 @@ -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 }, } diff --git a/cmd/unpin.go b/cmd/unpin.go index 8db3c56..43ae9d5 100644 --- a/cmd/unpin.go +++ b/cmd/unpin.go @@ -1,6 +1,10 @@ package cmd import ( + "fmt" + "strings" + + "github.com/apex/log" "github.com/marcosnils/bin/pkg/config" "github.com/spf13/cobra" ) @@ -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 @@ -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 }, }