-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
37 lines (32 loc) · 842 Bytes
/
init.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
package main
import (
"fmt"
"github.com/tvdburgt/passman/crypto"
"github.com/tvdburgt/passman/store"
"os"
)
var cmdInit = &Command{
Run: runInit,
UsageLine: "init [-f <file>]",
Short: "create empty passman store file",
Long: `
JSON-formatted, defaults to stdout.
-f, -file <store-file>
override default store file (default file location is $HOME/.pass_store
or $PASS_STORE, if set)
`,
}
func init() {
addFileFlag(cmdInit)
}
func runInit(cmd *Command, args []string) {
// Read file and make sure it doesn't exist
if _, err := os.Stat(storeFile); err == nil {
fatalf("passman init: '%s' already exists", storeFile)
}
passphrase := readVerifiedPassphrase()
defer crypto.Clear(passphrase)
s := store.NewStore()
writeStore(s, passphrase)
fmt.Printf("Initialized empty passman store at '%s'.\n", storeFile)
}