diff --git a/cmd/common.go b/cmd/common.go index 3f305ab..f229f2a 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -94,34 +94,40 @@ func (ts Tokens) String(i int) string { // Len - number of Token results func (ts Tokens) Len() int { return len(ts) } -func loadCachedTokens() (tokens []*Token, err error) { +func loadCachedTokens() ([]*Token, error) { fpath, err := ConfigPath(cacheFileName) if err != nil { - return + return nil, err } f, err := os.Open(fpath) if err != nil { - return + return nil, err } defer f.Close() + + tokens := []*Token{} err = json.NewDecoder(f).Decode(tokens) + if err != nil { + return nil, err + } + if verbose { fmt.Printf("Loaded cached providers from %v\n", fpath) } - return + return tokens, err } -func saveTokens(tks []*Token) (err error) { +func saveTokens(tks []*Token) error { regrPath, err := ConfigPath(cacheFileName) if err != nil { - return + return err } f, err := os.OpenFile(regrPath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) if err != nil { - return + return err } defer f.Close() @@ -129,12 +135,12 @@ func saveTokens(tks []*Token) (err error) { if err != nil { fmt.Printf("Error saving tokens: %v\n", err) - return + return err } if verbose { fmt.Printf("Saved tokens to file: %v\n", regrPath) } - return + return nil } func getTokensFromAuthyServer(devInfo *DeviceRegistration) ([]*Token, error) { @@ -295,6 +301,7 @@ func ConfigPath(fname string) (string, error) { return filepath.Join(devPath, fname), nil } + func promptAccountInfo() (phoneCC int, mobile string, err error) { var ( sc = bufio.NewScanner(os.Stdin) diff --git a/cmd/exec.go b/cmd/exec.go index 635a26d..d8811f9 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -116,9 +116,10 @@ func execCmdRun(tokenName, script, replacementToken string, dryRun bool) { fmt.Printf("code: %v\n", code) fmt.Printf("timeLeft: %v\n", timeLeft) fmt.Printf("orig script: %v\n", script) - fmt.Printf("script: [%v]\n", strings.Join(args, " ")) } + fmt.Printf("script: [%v]\n", strings.Join(args, " ")) + if dryRun { fmt.Printf("dry run exiting\n") return diff --git a/main.go b/main.go index 67cb5dc..aae8ea8 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( var ( // Version version tag - Version = "v0.12" + Version = "v0.13" // BuildDate date string of when build was performed filled in by -X compile flag BuildDate string