Skip to content

Commit

Permalink
Updating root cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
billykwooten committed Apr 6, 2021
1 parent c35ff15 commit 6f65086
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ package cmd

import (
"fmt"
"log"
"os"
"path"

"github.com/golang/glog"
homedir "github.com/mitchellh/go-homedir"
"github.com/billykwooten/go-ecobee/ecobee"
"github.com/rspier/go-ecobee/ecobee"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -68,9 +69,15 @@ func init() {
RootCmd.PersistentFlags().StringP("appid", "i", "", "app id")
RootCmd.PersistentFlags().StringP("authcache", "", "", "auth cache file")

viper.BindPFlag("thermostat", RootCmd.PersistentFlags().Lookup("thermostat"))
viper.BindPFlag("appid", RootCmd.PersistentFlags().Lookup("appid"))
viper.BindPFlag("authcache", RootCmd.PersistentFlags().Lookup("authcache"))
// This is a little messy... is there a nicer way to do this?
ck := func(err error) {
if err != nil {
log.Fatal("unexpected error setting up flag parsing!")
}
}
ck(viper.BindPFlag("thermostat", RootCmd.PersistentFlags().Lookup("thermostat")))
ck(viper.BindPFlag("appid", RootCmd.PersistentFlags().Lookup("appid")))
ck(viper.BindPFlag("authcache", RootCmd.PersistentFlags().Lookup("authcache")))
}

// initConfig reads in config file and ENV variables if set.
Expand Down Expand Up @@ -117,4 +124,4 @@ func client() *ecobee.Client {
glog.V(1).Infof("authCache: %s", ac)
// replace authCacheFile with authCache flag
return ecobee.NewClient(appID, ac)
}
}

0 comments on commit 6f65086

Please sign in to comment.