Skip to content

Commit

Permalink
added logout subcommand functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticrabbit committed Oct 26, 2021
1 parent 819d1de commit 2e2846b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
19 changes: 6 additions & 13 deletions cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,21 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// logoutCmd represents the logout command
var logoutCmd = &cobra.Command{
Use: "logout",
Short: "De-authorize Clickup CLI",
Long: `logout allows the user to revoke the access token for accessing a Clickup workspace`,
Short: "Log out of a Clickup workspace",
Long: `logout allows the user to delete the access token for accessing a Clickup workspace`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("logout called")
fmt.Println("deleted authentication token")
viper.Set("ctoken", "")
viper.WriteConfigAs(home + "/.clickup.yaml")
},
}

func init() {
rootCmd.AddCommand(logoutCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// logoutCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
logoutCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/clickup/clickup.yaml)")
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.clickup.yaml)")
}

// initConfig reads in config file and ENV variables if set.
// initConfig reads in config file, ENV variables if set, and determines authentication steps
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
Expand Down Expand Up @@ -64,7 +64,7 @@ func initConfig() {
panic("No Client Secret provided, check configuration")
}

if !viper.InConfig("ctoken") {
if !viper.InConfig("ctoken") || viper.GetString("ctoken") == "" {
token, err := internal.GetToken(viper.GetString("client_id"), viper.GetString("client_secret"), "4321")
if err != nil {
fmt.Fprintln(os.Stderr, "auth failed")
Expand Down

0 comments on commit 2e2846b

Please sign in to comment.