forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
880 lines (841 loc) · 25.3 KB
/
main.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
package main
import (
"context"
"fmt"
"io"
"log"
"os"
"os/signal"
"runtime"
"time"
"golang.org/x/crypto/ssh/terminal"
"github.com/blang/semver"
"github.com/fatih/color"
"github.com/justwatchcom/gopass/action"
"github.com/justwatchcom/gopass/backend/gpg"
"github.com/justwatchcom/gopass/config"
"github.com/justwatchcom/gopass/store/sub"
"github.com/justwatchcom/gopass/utils/ctxutil"
colorable "github.com/mattn/go-colorable"
"github.com/urfave/cli"
)
const (
name = "gopass"
)
var (
// Version is the released version of gopass
version string
// BuildTime is the time the binary was built
date string
// Commit is the git hash the binary was built from
commit string
)
func main() {
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
defer func() {
signal.Stop(sigChan)
cancel()
}()
go func() {
select {
case <-sigChan:
cancel()
case <-ctx.Done():
}
}()
// try to read config (if it exists)
cfg := config.Load()
// autosync
ctx = sub.WithAutoSync(ctx, cfg.Root.AutoSync)
// always trust
ctx = gpg.WithAlwaysTrust(ctx, true)
// ask for more
ctx = ctxutil.WithAskForMore(ctx, cfg.Root.AskForMore)
// clipboard timeout
ctx = ctxutil.WithClipTimeout(ctx, cfg.Root.ClipTimeout)
// no confirm
ctx = ctxutil.WithNoConfirm(ctx, cfg.Root.NoConfirm)
// no pager
ctx = ctxutil.WithNoPager(ctx, cfg.Root.NoPager)
// show safe content
ctx = ctxutil.WithShowSafeContent(ctx, cfg.Root.SafeContent)
// check recipients conflicts with always trust, make sure it's not enabled
// when always trust is
if gpg.IsAlwaysTrust(ctx) {
ctx = sub.WithCheckRecipients(ctx, false)
}
// debug flag
if gdb := os.Getenv("GOPASS_DEBUG"); gdb == "true" {
ctx = ctxutil.WithDebug(ctx, true)
}
// need this override for our integration tests
if nc := os.Getenv("GOPASS_NOCOLOR"); nc == "true" {
color.NoColor = true
ctx = ctxutil.WithColor(ctx, false)
}
// only emit color codes when stdout is a terminal
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
color.NoColor = true
ctx = ctxutil.WithColor(ctx, false)
ctx = ctxutil.WithTerminal(ctx, false)
ctx = ctxutil.WithInteractive(ctx, false)
}
// reading from stdin?
if info, err := os.Stdin.Stat(); err == nil && info.Mode()&os.ModeCharDevice == 0 {
ctx = ctxutil.WithInteractive(ctx, false)
ctx = ctxutil.WithStdin(ctx, true)
}
// disable colored output on windows since cmd.exe doesn't support ANSI color
// codes. Other terminal may do, but until we can figure that out better
// disable this for all terms on this platform
if runtime.GOOS == "windows" {
color.NoColor = true
ctx = ctxutil.WithColor(ctx, false)
}
cli.ErrWriter = errorWriter{
out: colorable.NewColorableStderr(),
}
sv, err := semver.Parse(version)
if err != nil {
sv = semver.Version{
Major: 1,
Minor: 4,
Patch: 0,
Pre: []semver.PRVersion{
semver.PRVersion{VersionStr: "git"},
},
Build: []string{"HEAD"},
}
}
// only update version field in config, if it's older than this build
csv, err := semver.Parse(cfg.Version)
if err != nil || csv.LT(sv) {
cfg.Version = sv.String()
if err := cfg.Save(); err != nil {
fmt.Println(color.RedString("Failed to save config: %s", err))
}
}
cli.VersionPrinter = makeVersionPrinter(sv)
action := action.New(ctx, cfg, sv)
// set some action callbacks
if !cfg.Root.AutoImport {
ctx = sub.WithImportFunc(ctx, action.AskForKeyImport)
}
if !cfg.Root.NoConfirm {
ctx = sub.WithRecipientFunc(ctx, action.ConfirmRecipients)
}
ctx = sub.WithFsckFunc(ctx, action.AskForConfirmation)
app := cli.NewApp()
app.Name = name
app.Version = sv.String()
app.Usage = "The standard unix password manager - rewritten in Go"
app.EnableBashCompletion = true
app.BashComplete = func(c *cli.Context) {
cli.DefaultAppComplete(c)
action.Complete(c)
}
app.Action = func(c *cli.Context) error {
if err := action.Initialized(ctx, c); err != nil {
return err
}
if c.Args().Present() {
return action.Show(withGlobalFlags(ctx, c), c)
}
return action.List(withGlobalFlags(ctx, c), c)
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "yes",
Usage: "Assume yes on all yes/no questions or use the default on all others",
},
cli.BoolFlag{
Name: "clip, c",
Usage: "Copy the first line of the secret into the clipboard",
},
}
app.Commands = []cli.Command{
{
Name: "audit",
Usage: "Audit passwords for common flaws",
Description: "To check passwords for common flaws (e.g. too short or from a dictionary)",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Audit(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.IntFlag{
Name: "jobs, j",
Usage: "The number of jobs to run concurrently when auditing",
Value: 1,
},
},
Subcommands: []cli.Command{
{
Name: "hibp",
Usage: "Check all secrets against the public haveibeenpwned.com dumps",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.HIBP(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force to move the secret and overwrite existing one",
},
},
},
},
},
{
Name: "binary",
Usage: "Work with binary blobs",
Aliases: []string{"bin"},
Subcommands: []cli.Command{
{
Name: "cat",
Usage: "Print content of a secret to stdout or insert from stdin",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.BinaryCat(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
},
{
Name: "sum",
Usage: "Compute the SHA256 sum of a decoded secret",
Aliases: []string{"sha", "sha256"},
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.BinarySum(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
},
{
Name: "copy",
Usage: "Copy files from or to the password store",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Aliases: []string{"cp"},
Action: func(c *cli.Context) error {
return action.BinaryCopy(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force to move the secret and overwrite existing one",
},
},
},
{
Name: "move",
Usage: "Move files from or to the password store",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Aliases: []string{"mv"},
Action: func(c *cli.Context) error {
return action.BinaryMove(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force to move the secret and overwrite existing one",
},
},
},
},
},
{
Name: "clone",
Usage: "Clone a new store",
Description: "To clone a remote repo",
Action: func(c *cli.Context) error {
return action.Clone(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "path",
Usage: "Path to clone the repo to",
},
},
},
{
Name: "completion",
Usage: "Source the output with bash or zsh to get auto completion",
Subcommands: []cli.Command{{
Name: "bash",
Usage: "Source for auto completion in bash",
Action: action.CompletionBash,
}, {
Name: "zsh",
Usage: "Source for auto completion in zsh",
Action: action.CompletionZSH,
}},
},
{
Name: "config",
Usage: "Edit configuration",
Description: "To manipulate the gopass configuration",
Action: func(c *cli.Context) error {
return action.Config(withGlobalFlags(ctx, c), c)
},
BashComplete: action.ConfigComplete,
Flags: []cli.Flag{
cli.StringFlag{
Name: "store",
Usage: "Set value to substore config",
},
},
},
{
Name: "copy",
Aliases: []string{"cp"},
Usage: "Copies old-path to new-path, optionally forcefully, selectively reencrypting.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Copy(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force to copy the secret and overwrite existing one",
},
},
},
{
Name: "delete",
Usage: "Remove existing secret or directory, optionally forcefully.",
Aliases: []string{"remove", "rm"},
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Delete(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "recursive, r",
Usage: "f",
},
cli.BoolFlag{
Name: "force, f",
Usage: "Force to delete the secret",
},
},
},
{
Name: "edit",
Usage: "Insert a new secret or edit an existing secret using $EDITOR.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Edit(withGlobalFlags(ctx, c), c)
},
Aliases: []string{"set"},
BashComplete: action.Complete,
},
{
Name: "find",
Usage: "List secrets that match the search term.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Find(withGlobalFlags(ctx, c), c)
},
Aliases: []string{"search"},
BashComplete: action.Complete,
},
{
Name: "fsck",
Usage: "Check store integrity",
Description: "Check integrity of all stores",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Fsck(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.BoolFlag{
Name: "check, c",
Usage: "Only report",
},
cli.BoolFlag{
Name: "force, f",
Usage: "Auto-correct any errors, do not ask",
},
},
},
{
Name: "generate",
Usage: "Generate a new password of the specified length with optionally no symbols.",
Description: "" +
"Generate a new password of the specified length with optionally no symbols. " +
"Optionally put it on the clipboard and clear board after 45 seconds. " +
"Prompt before overwriting existing password unless forced. " +
"It will replace only the first line of an existing file with a new password.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Generate(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "clip, c",
Usage: "Copy the password into the clipboard",
},
cli.BoolFlag{
Name: "force, f",
Usage: "Force to overwrite existing password",
},
cli.BoolFlag{
Name: "edit, e",
Usage: "Open secret for editing after generating a password",
},
cli.BoolFlag{
Name: "no-symbols, n",
Usage: "Do not include symbols in the password",
Hidden: true,
},
cli.BoolFlag{
Name: "symbols, s",
Usage: "Use symbols in the password",
},
},
},
{
Name: "jsonapi",
Usage: "Run gopass as jsonapi e.g. for browser plugins",
Description: "Setup and run gopass as native messaging hosts, e.g. for browser plugins.",
Subcommands: []cli.Command{
{
Name: "listen",
Usage: "Listen and respond to messages via stdin/stdout",
Description: "Gopass is started in listen mode from browser plugins using a wrapper specified in native messaging host manifests",
Action: func(c *cli.Context) error {
return action.JSONAPI(withGlobalFlags(ctx, c), c)
},
},
{
Name: "configure",
Usage: "Setup gopass native messaging manifest for selected browser",
Description: "To access gopass from browser plugins, a native app manifest must be installed at the correct location",
Action: func(c *cli.Context) error {
return action.SetupNativeMessaging(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "browser",
Usage: "One of 'chrome' and 'firefox'",
},
cli.StringFlag{
Name: "path",
Usage: "Path to install 'gopass_wrapper.sh' to",
},
cli.BoolFlag{
Name: "global",
Usage: "Install for all users, requires superuser rights",
},
cli.StringFlag{
Name: "libpath",
Usage: "Library path for global installation on linux. Default is /usr/lib",
},
cli.BoolFlag{
Name: "print-only",
Usage: "only print installation summary but do not actually create any files",
},
},
},
},
},
{
Name: "totp",
Usage: "Generate time based token from stored secret",
Description: "Tries to parse the saved string as a time-based one-time password secret and generate a token based on the current time",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.TOTP(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "clip, c",
Usage: "Copy the time based token into the clipboard",
},
},
},
{
Name: "git",
Usage: "Do git things",
Description: "If the password store is a git repository, execute a git command specified by git-command-args.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Git(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "store, s",
Usage: "Store to operate on",
},
cli.BoolFlag{
Name: "no-recurse, n",
Usage: "Do not recurse to mounted sub-stores",
},
cli.BoolFlag{
Name: "force, f",
Usage: "Print errors but continue",
},
},
Subcommands: []cli.Command{
{
Name: "init",
Usage: "Init git repo",
Description: "Create and initialize a new git repo in the store",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.GitInit(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "store",
Usage: "Store to operate on",
},
cli.StringFlag{
Name: "sign-key",
Usage: "GPG Key to sign commits",
},
},
},
},
},
{
Name: "grep",
Usage: "Search for secrets files containing search-string when decrypted.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Grep(withGlobalFlags(ctx, c), c)
},
},
{
Name: "init",
Usage: "Initialize new password storage and use gpg-id for encryption.",
Description: "" +
"Initialize new password storage and use gpg-id for encryption.",
Action: func(c *cli.Context) error {
return action.Init(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "path, p",
Usage: "Set the sub store path to operate on",
},
cli.StringFlag{
Name: "store, s",
Usage: "Set the name of the sub store",
},
cli.BoolFlag{
Name: "nogit",
Usage: "Do not init git repo",
},
},
},
{
Name: "insert",
Usage: "Insert new secret",
Description: "" +
"Insert new secret. Optionally, echo the secret back to the console during entry. " +
"Or, optionally, the entry may be multiline. " +
"Prompt before overwriting existing secret unless forced.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Insert(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "echo, e",
Usage: "Display secret while typing",
},
cli.BoolFlag{
Name: "multiline, m",
Usage: "Insert using $EDITOR",
},
cli.BoolFlag{
Name: "force, f",
Usage: "Overwrite any existing secret and do not prompt to confirm recipients",
},
},
},
{
Name: "list",
Usage: "List secrets.",
Aliases: []string{"ls"},
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.List(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.IntFlag{
Name: "limit, l",
Usage: "Max tree depth",
},
cli.BoolFlag{
Name: "flat, f",
Usage: "Print flat list",
},
cli.BoolFlag{
Name: "strip-prefix, s",
Usage: "Strip prefix from filtered entries",
},
},
},
{
Name: "move",
Aliases: []string{"mv"},
Usage: "Renames or moves old-path to new-path, optionally forcefully, selectively reencrypting.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Move(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "Force to move the secret and overwrite existing one",
},
},
},
{
Name: "mounts",
Usage: "Edit mounts",
Description: "To manipulate gopass mounts",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.MountsPrint(withGlobalFlags(ctx, c), c)
},
Subcommands: []cli.Command{
{
Name: "add",
Usage: "Add mount",
Description: "To add a new mounted sub store",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.MountAdd(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "init, i",
Usage: "Init the store with the given recipient key",
},
},
},
{
Name: "remove",
Aliases: []string{"rm"},
Usage: "Remove mount",
Description: "To remove a mounted sub store",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.MountRemove(withGlobalFlags(ctx, c), c)
},
BashComplete: action.MountsComplete,
},
},
},
{
Name: "recipients",
Usage: "List Recipients",
Description: "To show all recipients",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.RecipientsPrint(withGlobalFlags(ctx, c), c)
},
Subcommands: []cli.Command{
{
Name: "add",
Usage: "Add any number of Recipients",
Description: "To add any number of recipients to a store",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.RecipientsAdd(withGlobalFlags(ctx, c), c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "store",
Usage: "Store to operate on",
},
},
},
{
Name: "remove",
Aliases: []string{"rm"},
Usage: "Remove any number of Recipients",
Description: "To remove any number of recipients from a store",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.RecipientsRemove(withGlobalFlags(ctx, c), c)
},
BashComplete: func(c *cli.Context) {
action.RecipientsComplete(ctx, c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "store",
Usage: "Store to operate on",
},
},
},
},
},
{
Name: "show",
Usage: "Show existing secret and optionally put its first line on the clipboard.",
Description: "" +
"Show existing secret and optionally put its first line on the clipboard. " +
"If put on the clipboard, it will be cleared in 45 seconds.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Show(withGlobalFlags(ctx, c), c)
},
BashComplete: action.Complete,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "clip, c",
Usage: "Copy the first line of the secret into the clipboard",
},
cli.BoolFlag{
Name: "qr",
Usage: "Print the first line of the secret as QR Code",
},
cli.BoolFlag{
Name: "force, f",
Usage: "Display the password even if safecontent is enabled",
},
},
},
{
Name: "sync",
Usage: "Sync all local stores with their remotes (if any)",
Description: "" +
"Sync all local stores with their git remotes, if any, and check" +
"any possibly affected gpg keys.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Sync(withGlobalFlags(ctx, c), c)
},
},
{
Name: "templates",
Usage: "List and edit secret templates.",
Description: "" +
"List existing templates in the password store and allow for editing " +
"and creating them.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.TemplatesPrint(withGlobalFlags(ctx, c), c)
},
Subcommands: []cli.Command{
{
Name: "show",
Usage: "Show a secret template.",
Description: "Dispaly an existing template",
Aliases: []string{"cat"},
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.TemplatePrint(withGlobalFlags(ctx, c), c)
},
BashComplete: action.TemplatesComplete,
},
{
Name: "edit",
Usage: "Edit secret templates.",
Description: "Edit an existing or new template",
Aliases: []string{"create", "new"},
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.TemplateEdit(withGlobalFlags(ctx, c), c)
},
BashComplete: action.TemplatesComplete,
},
{
Name: "remove",
Aliases: []string{"rm"},
Usage: "Remove secret templates.",
Description: "Remove an existing template",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.TemplateRemove(withGlobalFlags(ctx, c), c)
},
BashComplete: action.TemplatesComplete,
},
},
},
{
Name: "unclip",
Usage: "Internal command to clear clipboard",
Description: "Clear the clipboard if the content matches the checksum",
Action: func(c *cli.Context) error {
return action.Unclip(withGlobalFlags(ctx, c), c)
},
Hidden: true,
Flags: []cli.Flag{
cli.IntFlag{
Name: "timeout",
Usage: "Time to wait",
},
},
},
{
Name: "version",
Usage: "Print gopass version",
Description: "Display version and build time information",
Action: func(c *cli.Context) error {
return action.Version(withGlobalFlags(ctx, c), c)
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func makeVersionPrinter(sv semver.Version) func(c *cli.Context) {
return func(c *cli.Context) {
buildtime := ""
if bt, err := time.Parse("2006-01-02T15:04:05-0700", date); err == nil {
buildtime = bt.Format("2006-01-02 15:04:05")
}
buildInfo := ""
if commit != "" {
buildInfo = commit
}
if buildtime != "" {
if buildInfo != "" {
buildInfo += " "
}
buildInfo += buildtime
}
if buildInfo != "" {
buildInfo = "(" + buildInfo + ") "
}
fmt.Printf("%s %s %s%s %s %s\n",
name,
sv.String(),
buildInfo,
runtime.Version(),
runtime.GOOS,
runtime.GOARCH,
)
}
}
type errorWriter struct {
out io.Writer
}
func (e errorWriter) Write(p []byte) (int, error) {
return e.out.Write([]byte("\n" + color.RedString("Error: %s", p)))
}
func withGlobalFlags(ctx context.Context, c *cli.Context) context.Context {
if c.GlobalBool("yes") {
ctx = ctxutil.WithAlwaysYes(ctx, true)
}
return ctx
}