Skip to content

Commit

Permalink
Add configuration flag and move flags out of main.
Browse files Browse the repository at this point in the history
  • Loading branch information
hacktobeer committed Dec 18, 2020
1 parent b7be452 commit d3b05f6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions utils/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ var (
version = "development"
commit = "development"
date = "development"

versionFlag = flag.Bool("version", false, "Show build version information")
configFlag = flag.String("config", "gopanasonic.yaml", "Path of YAML configuration file")
listFlag = flag.Bool("list", false, "List available devices")
deviceFlag = flag.String("device", "", "Device to issue command to")
onFlag = flag.Bool("on", false, "Turn device on")
offFlag = flag.Bool("off", false, "Turn device off")
tempFlag = flag.Float64("temp", 0, "Set the temperature (in Celsius)")
modeFlag = flag.String("mode", "", "Set mode: auto,heat,cool,dry,fan")
statusFlag = flag.Bool("status", false, "Display current status of device")
historyFlag = flag.String("history", "", "Display history: day,week,month,year")
)

func readConfig() {
viper.SetConfigName("gopanasonic")
viper.SetConfigFile(*configFlag)
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %s", err))
}
}

func main() {
versionFlag := flag.Bool("version", false, "Show build version information")
listFlag := flag.Bool("list", false, "List available devices")
deviceFlag := flag.String("device", "", "Device to issue command to")
onFlag := flag.Bool("on", false, "Turn device on")
offFlag := flag.Bool("off", false, "Turn device off")
tempFlag := flag.Float64("temp", 0, "Set the temperature (in Celsius)")
modeFlag := flag.String("mode", "", "Set mode: auto,heat,cool,dry,fan")
statusFlag := flag.Bool("status", false, "Display current status of device")
historyFlag := flag.String("history", "", "Display history: day,week,month,year")

if len(os.Args) < 2 {
flag.PrintDefaults()
os.Exit(1)
Expand Down

0 comments on commit d3b05f6

Please sign in to comment.