Skip to content

Commit

Permalink
Set state on profile
Browse files Browse the repository at this point in the history
  • Loading branch information
bahner committed Mar 17, 2024
1 parent ed2c66e commit f78a5ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cmd/actor/mode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/bahner/go-ma-actor/config"
"github.com/spf13/pflag"
)

const (
defaultPongMode = false
defaultRelayMode = false
)

func init() {

// NB! Other mode pflags are in the proper mode packages.
pflag.Bool("pong", defaultPongMode, "Pong mode with automatic replies and no UI.")
pflag.Bool("pong-fortune", config.DEFAULT_PONG_FORTUNE_MODE, "Reply with a fortune cookie, instead of a static message, if availble.")
pflag.Bool("relay", defaultRelayMode, "Relay mode with no actor, to just listen and relay messages.")

}
6 changes: 6 additions & 0 deletions config/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ func Mode() string {
}

if PongMode() {

// This only sets fallback when not specified on command line
SetProfile(pong)
return pong
}

if RelayMode() {

// This only sets fallback when not specified on command line
SetProfile(relay)
return relay
}

Expand Down
8 changes: 7 additions & 1 deletion config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "github.com/spf13/pflag"

// NB! This file is used early in the initialization process, so it can't depend on other packages.

var profile string = "actor"

// Profile is the mode unless overridden by the profile flag.
func Profile() string {

Expand All @@ -14,5 +16,9 @@ func Profile() string {
}
}

return Mode()
return profile
}

func SetProfile(p string) {
profile = p
}

0 comments on commit f78a5ca

Please sign in to comment.