forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.go
34 lines (25 loc) · 757 Bytes
/
move.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
package action
import (
"context"
"fmt"
"github.com/justwatchcom/gopass/pkg/termio"
"github.com/urfave/cli"
)
// Move the content from one secret to another
func (s *Action) Move(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
if len(c.Args()) != 2 {
return ExitError(ctx, ExitUsage, nil, "Usage: %s mv old-path new-path", s.Name)
}
from := c.Args()[0]
to := c.Args()[1]
if !force {
if s.Store.Exists(ctx, to) && !termio.AskForConfirmation(ctx, fmt.Sprintf("%s already exists. Overwrite it?", to)) {
return ExitError(ctx, ExitAborted, nil, "not overwriting your current secret")
}
}
if err := s.Store.Move(ctx, from, to); err != nil {
return ExitError(ctx, ExitUnknown, err, "%s", err)
}
return nil
}