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
|
diff --git a/cmd/spectre/main.go b/cmd/spectre/main.go
index 25bffd4c39bd4c0be8b3a77113dcae31f7c02888..d23679f3ea3f3d4273be06722d90f2f8a59f0bdd 100644
--- a/cmd/spectre/main.go
+++ b/cmd/spectre/main.go
@@ -6,16 +6,17 @@ "fmt"
"os"
"strings"
+ "github.com/atotto/clipboard"
"go.jolheiser.com/go-spectre"
)
func main() {
- pw, err := maine(os.Args[1:])
+ msg, err := maine(os.Args[1:])
if err != nil {
fmt.Println(err)
return
}
- fmt.Println(pw)
+ fmt.Println(msg)
}
func maine(args []string) (string, error) {
@@ -48,6 +49,7 @@ return
}
fs.Func("template", "template [maximum, long, medium, short, pin, name, phrase, basic]", templateFn)
fs.Func("t", "--template", templateFn)
+ printFlag := fs.Bool("print", false, "Print out password instead of copying to clipboard")
if err := fs.Parse(args); err != nil {
return "", err
@@ -83,11 +85,20 @@ if err != nil {
return "", err
}
- return s.Site(fs.Arg(0),
+ pw := s.Site(fs.Arg(0),
spectre.WithScope(scopeFlag),
spectre.WithTemplate(templateFlag),
spectre.WithCounter(*counterFlag),
- ), nil
+ )
+
+ if *printFlag {
+ return pw, nil
+ }
+
+ if err := clipboard.WriteAll(pw); err != nil {
+ return fmt.Sprintf("could not write password to clipboard\n%v\nalternatively, run spectre with the --print flag to print to stdout", err), nil
+ }
+ return "Password copied to clipboard", nil
}
type requiredArgs struct {
|