-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.go
45 lines (37 loc) · 895 Bytes
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"context"
"fmt"
multierror "github.com/hashicorp/go-multierror"
"github.com/mitchellh/cli"
"github.com/pkg/errors"
)
type DeleteCommand struct {
ui UI
}
func (d *DeleteCommand) Help() string {
return "Usage: star delete <name>"
}
func (d *DeleteCommand) Run(args []string) int {
if len(args) == 0 {
d.ui.ErrPrintln(d.Help())
return 1
}
var result error
for _, name := range args {
if err := repo.Bookmark.Delete(context.Background(), &Bookmark{Name: name}); err != nil {
result = multierror.Append(result, errors.Wrapf(err, "no such bookmark: %s", name))
}
}
if result != nil {
d.ui.ErrPrintln(fmt.Sprintf("failed to delete some bookmarks: %s", result))
return 1
}
return 0
}
func (d *DeleteCommand) Synopsis() string {
return "delete a bookmark"
}
func newDeleteCommand() (cli.Command, error) {
return &DeleteCommand{ui: ui}, nil
}