Skip to content

Commit 14dff9e

Browse files
committed
New command: totp temp
1 parent 735e220 commit 14dff9e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Available Commands:
2929
help Help about any command
3030
list List all registered TOTP codes
3131
scan Scan a QR code image
32+
temp Get a TOTP code from a secret without saving it to the keychain
3233

3334
Flags:
3435
-h, --help help for ./totp
@@ -52,6 +53,10 @@ $ totp get google
5253

5354
$ totp delete google
5455
Successfully deleted "google".
56+
57+
$ totp temp
58+
Type secret: ABCDEFGHIJKLMNOPQRSTUVWXYZ
59+
123456
5560
```
5661

5762
 

main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,27 @@ func main() {
206206
},
207207
}
208208

209+
var cmdTemp = &cobra.Command{
210+
Use: "temp",
211+
Short: "Get a TOTP code from a secret without saving it to the keychain",
212+
Args: cobra.NoArgs,
213+
RunE: func(cmd *cobra.Command, args []string) error {
214+
// Read secret from stdin
215+
var secret string
216+
fmt.Print("Type secret: ")
217+
fmt.Scanln(&secret)
218+
if secret == "" {
219+
return errors.New("No secret was given")
220+
}
221+
222+
// Generate a TOTP code
223+
fmt.Println(gotp.NewDefaultTOTP(secret).Now())
224+
return nil
225+
},
226+
}
227+
209228
var rootCmd = &cobra.Command{Use: os.Args[0], Version: "1.0.1"}
210-
rootCmd.AddCommand(cmdScan, cmdAdd, cmdList, cmdGet, cmdDelete)
229+
rootCmd.AddCommand(cmdScan, cmdAdd, cmdList, cmdGet, cmdDelete, cmdTemp)
211230
if err := rootCmd.Execute(); err != nil {
212231
fmt.Println(err)
213232
os.Exit(1)

0 commit comments

Comments
 (0)