Skip to content

Commit

Permalink
chore: add various convenience options for brew formulae #9
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie0129 committed Oct 8, 2024
1 parent 0dc59eb commit 0d9b44c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
11 changes: 10 additions & 1 deletion cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func NewCommand() *cobra.Command {

globalFlags := cmd.PersistentFlags()
globalFlags.StringVarP(&logLevel, "log-level", "l", "info", "log level (trace, debug, info, warn, error, fatal, panic)")
globalFlags.StringVar(&configPath, "config", configPath, "config file path")
globalFlags.StringVar(&unixSocketPath, "daemon-socket", unixSocketPath, "batt daemon unix socket path")

for _, i := range commandGroups {
cmd.AddGroup(&cobra.Group{
Expand Down Expand Up @@ -81,7 +83,7 @@ func NewVersionCommand() *cobra.Command {

// NewDaemonCommand .
func NewDaemonCommand() *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "daemon",
Hidden: true,
Short: "Run batt daemon in the foreground",
Expand All @@ -91,6 +93,13 @@ func NewDaemonCommand() *cobra.Command {
runDaemon()
},
}

f := cmd.Flags()

f.BoolVar(&alwaysAllowNonRootAccess, "always-allow-non-root-access", false,
"Always allow non-root users to access the daemon.")

return cmd
}

// NewInstallCommand .
Expand Down
9 changes: 9 additions & 0 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func setupRoutes() *gin.Engine {
return router
}

var (
alwaysAllowNonRootAccess = false
)

func runDaemon() {
router := setupRoutes()

Expand All @@ -54,6 +58,11 @@ func runDaemon() {
}
logrus.Infof("config loaded: %#v", config)

if alwaysAllowNonRootAccess {
config.AllowNonRootAccess = true
logrus.Info("alwaysAllowNonRootAccess is set to true, allowing non-root access")
}

// Receive SIGHUP to reload config
go func() {
sigc := make(chan os.Signal, 1)
Expand Down
19 changes: 11 additions & 8 deletions hack/cc.chlc.batt.plist
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>cc.chlc.batt</string>
<!-- Make it interactive to avoid batt being stopped by macOS, which could cause malfunctions of batt. -->
<key>ProcessType</key>
<string>Interactive</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/batt</string>
<string>daemon</string>
<string>-l=debug</string>
<string>--log-level=debug</string>
</array>
<key>StandardOutPath</key>
<string>/tmp/batt.log</string>
<key>StandardErrorPath</key>
<string>/tmp/batt.log</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/batt.log</string>
<key>StandardOutPath</key>
<string>/tmp/batt.log</string>
</dict>
</plist>

0 comments on commit 0d9b44c

Please sign in to comment.