Skip to content

Commit

Permalink
feat(cmd): auto-detect whether to run in headless mode or not
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Nov 23, 2023
1 parent 1375fa9 commit 7c77032
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package cmd

import (
_ "net/http/pprof"
"os"

"github.com/joshuar/go-hass-agent/internal/agent"
"github.com/joshuar/go-hass-agent/internal/logging"
Expand Down Expand Up @@ -62,10 +63,15 @@ func init() {
"enable profiling (default is false)")
rootCmd.PersistentFlags().StringVar(&debugID, "debugid", "",
"specify a custom app ID (for debugging)")
rootCmd.PersistentFlags().BoolVar(&headlessFlag, "terminal", false,
rootCmd.PersistentFlags().BoolVar(&headlessFlag, "terminal", defaultHeadless(),
"run in terminal (without a GUI)")

rootCmd.AddCommand(infoCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(registerCmd)
}

func defaultHeadless() bool {
_, v := os.LookupEnv("DISPLAY")
return !v
}

0 comments on commit 7c77032

Please sign in to comment.