-
Notifications
You must be signed in to change notification settings - Fork 1
/
token.go
39 lines (33 loc) · 979 Bytes
/
token.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
package cmd
import (
"fmt"
"github.com/emersonmello/claro/utils"
"github.com/spf13/cobra"
)
// tokenCmd represents the token command
var tokenCmd = &cobra.Command{
Use: "token <add|del>",
Short: "Add or remove GitHub Personal Access Token in OS Keychain",
Long: `Add or remove GitHub Personal Access Token in OS Keychain
If the OS Keychain is not available then you can store the token in the config file`,
Example: "claro config token add",
ValidArgs: []string{"add", "del"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "add":
utils.SaveGHToken(utils.ReadTokenFromStdIn())
case "del":
if !utils.PromptUser("Do you want to remove the token from the keychain? (y/N):", "no") {
if e := utils.DeletePasswordItem(); e == nil {
fmt.Println("Done!")
} else {
checkError(e)
}
}
}
},
}
func init() {
configCmd.AddCommand(tokenCmd)
}