-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
84 lines (73 loc) · 1.79 KB
/
main.go
File metadata and controls
84 lines (73 loc) · 1.79 KB
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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"path"
"syscall"
"time"
"github.com/jmhobbs/authy-cli/api"
"github.com/jmhobbs/authy-cli/commands"
"github.com/jmhobbs/authy-cli/flags"
"github.com/jmhobbs/authy-cli/store"
"github.com/peterbourgon/ff/v3/ffcli"
"golang.org/x/term"
)
func main() {
logFile := time.Now().Format("2006-01-02T15:04:05") + ".har"
authy := api.New("", "")
home, err := os.UserHomeDir()
if err != nil {
log.Fatalf("error: %v", err)
}
db, err := store.New(path.Join(home, ".authy-cli"), func() (string, error) {
var passphrase string = flags.StoragePassword()
if passphrase != "" {
return passphrase, nil
}
fmt.Fprint(os.Stderr, "Enter Storage Password: ")
passphraseBytes, err := term.ReadPassword(int(syscall.Stdin))
fmt.Fprintln(os.Stderr)
return string(passphraseBytes), err
})
if err != nil {
log.Fatalf("error: %v", err)
}
defer shutdownHandler(false, authy, logFile)
// defer won't run in the case of ctrl-c
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
shutdownHandler(true, authy, logFile)
os.Exit(1)
}()
var rootFlagSet = flag.NewFlagSet("authy-cli", flag.ExitOnError)
flags.Register(rootFlagSet)
root := &ffcli.Command{
ShortUsage: "authy-cli [flags] <subcommand>",
FlagSet: rootFlagSet,
Subcommands: []*ffcli.Command{
commands.Register(db, authy),
commands.Sync(db, authy),
commands.Export(db),
commands.Token(db),
commands.List(db),
commands.Unlock(db),
commands.Version,
},
Exec: func(context.Context, []string) error {
return flag.ErrHelp
},
}
if err := root.ParseAndRun(context.Background(), os.Args[1:]); err != nil {
if err == flag.ErrHelp {
return
}
log.Printf("error: %v", err)
shutdownHandler(true, authy, logFile)
}
}