forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount.go
69 lines (61 loc) · 1.62 KB
/
mount.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package action
import (
"fmt"
"github.com/fatih/color"
"github.com/justwatchcom/gopass/tree"
"github.com/urfave/cli"
)
// MountRemove removes an existing mount
func (s *Action) MountRemove(c *cli.Context) error {
if len(c.Args()) != 1 {
return fmt.Errorf("usage: gopass mount remove [alias]")
}
if err := s.Store.RemoveMount(c.Args()[0]); err != nil {
return err
}
if err := writeConfig(s.Store); err != nil {
return err
}
color.Green("Password Store %s umounted", c.Args()[0])
return nil
}
// MountsPrint prints all existing mounts
func (s *Action) MountsPrint(c *cli.Context) error {
if len(s.Store.Mount) < 1 {
fmt.Println("No mounts")
return nil
}
root := tree.New(color.GreenString(fmt.Sprintf("gopass (%s)", s.Store.Path)))
for alias, path := range s.Store.Mount {
if err := root.AddMount(alias, path); err != nil {
fmt.Printf("Failed to add mount: %s\n", err)
}
}
fmt.Fprintln(color.Output, root.Format())
return nil
}
// MountsComplete will print a list of existings mount points for bash
// completion
func (s *Action) MountsComplete(*cli.Context) {
for alias := range s.Store.Mount {
fmt.Println(alias)
}
}
// MountAdd adds a new mount
func (s *Action) MountAdd(c *cli.Context) error {
if len(c.Args()) != 2 {
return fmt.Errorf("usage: gopass mount add [alias] [path]")
}
keys := make([]string, 0, 1)
if k := c.String("init"); k != "" {
keys = append(keys, k)
}
if err := s.Store.AddMount(c.Args()[0], c.Args()[1], keys...); err != nil {
return err
}
if err := writeConfig(s.Store); err != nil {
return err
}
color.Green("Mounted %s as %s", c.Args()[0], c.Args()[1])
return nil
}