forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy.go
44 lines (34 loc) · 766 Bytes
/
copy.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
package action
import (
"fmt"
"github.com/urfave/cli"
)
// Copy the contents of a file to another one
func (s *Action) Copy(c *cli.Context) error {
force := c.Bool("force")
if len(c.Args()) != 2 {
return fmt.Errorf("Usage: gopass cp old-path new-path")
}
from := c.Args()[0]
to := c.Args()[1]
exists, err := s.Store.Exists(from)
if err != nil {
return err
}
if !exists {
return fmt.Errorf("%s doesn't exists", from)
}
if !force {
exists, err := s.Store.Exists(to)
if err != nil {
return err
}
if exists && !askForConfirmation(fmt.Sprintf("%s already exists. Overwrite it?", to)) {
return fmt.Errorf("not overwriting your current secret")
}
}
if err := s.Store.Copy(from, to); err != nil {
return err
}
return nil
}