forked from kopia/kopia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_content_delete.go
More file actions
40 lines (29 loc) · 877 Bytes
/
Copy pathcommand_content_delete.go
File metadata and controls
40 lines (29 loc) · 877 Bytes
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
package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
)
type commandContentDelete struct {
ids []string
svc appServices
}
func (c *commandContentDelete) setup(svc appServices, parent commandParent) {
cmd := parent.Command("delete", "Remove content").Alias("remove").Alias("rm").Hidden()
cmd.Arg("id", "IDs of content to remove").Required().StringsVar(&c.ids)
cmd.Action(svc.directRepositoryWriteAction(c.run))
c.svc = svc
}
func (c *commandContentDelete) run(ctx context.Context, rep repo.DirectRepositoryWriter) error {
c.svc.dangerousCommand()
contentIDs, err := toContentIDs(c.ids)
if err != nil {
return err
}
for _, contentID := range contentIDs {
if err := rep.ContentManager().DeleteContent(ctx, contentID); err != nil {
return errors.Wrapf(err, "error deleting content %v", contentID)
}
}
return nil
}