From 3a21cee4d1972b9d8af0e73958fa873133650f79 Mon Sep 17 00:00:00 2001 From: Dan O'Neill Date: Thu, 23 Nov 2023 10:34:33 -0800 Subject: [PATCH 1/2] update config comment out path until we implement out of app directory --- cmd/root.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 3918f2b..0ec44fc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,7 +13,8 @@ import ( const PROGRAM_NAME string = "er" const CONFIG_TYPE string = ".toml" -const CONFIG_PATH string = "/Users/dano/.config/er/" + +// const CONFIG_PATH string = "/Users/dano/.config/er/" // ---------------------------------------------- // command @@ -44,6 +45,6 @@ func init() { func initConfig() { viper.SetConfigName(PROGRAM_NAME) - viper.SetConfigType(CONFIG_TYPE) - viper.AddConfigPath(CONFIG_PATH) + viper.SetConfigType("toml") + viper.AddConfigPath(".") } From 86cc3ceeea8026afc6377bbedc5d65049505ae3a Mon Sep 17 00:00:00 2001 From: Dan O'Neill Date: Thu, 23 Nov 2023 10:34:53 -0800 Subject: [PATCH 2/2] initial token impl --- cmd/token.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cmd/token.go diff --git a/cmd/token.go b/cmd/token.go new file mode 100644 index 0000000..3619950 --- /dev/null +++ b/cmd/token.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// ---------------------------------------------- +// token command +// ---------------------------------------------- + +var tokenCmd = &cobra.Command{ + Use: "token", + Short: "Display token", + Long: `Return the current users token`, + Run: func(cmd *cobra.Command, args []string) { + token() + }, +} + +// ---------------------------------------------- +// funtions +// ---------------------------------------------- + +func token() { + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); ok { + fmt.Println("Error: er not configured properly, try reauthenticating") + } else { + fmt.Println("Error:", err) + } + } else { + var token = viper.Get("oauth_token") + fmt.Println(token) + } +} + +// ---------------------------------------------- +// initialize +// ---------------------------------------------- + +func init() { + authCmd.AddCommand(tokenCmd) +}