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(".") } 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) +}