43 lines
733 B
Go
43 lines
733 B
Go
|
package admincli
|
||
|
|
||
|
import (
|
||
|
"flag"
|
||
|
"fmt"
|
||
|
"slices"
|
||
|
"strings"
|
||
|
|
||
|
"maps"
|
||
|
)
|
||
|
|
||
|
var actionMap = map[string]func(c Command){
|
||
|
"play-random": PlayRandomAction,
|
||
|
"play": PlayAction,
|
||
|
"stop": StopAction,
|
||
|
"now-playing": NowPlayingAction,
|
||
|
}
|
||
|
|
||
|
func getActionNames() string {
|
||
|
return strings.Join(slices.Collect(maps.Keys(actionMap)), ", ")
|
||
|
}
|
||
|
|
||
|
type Command struct {
|
||
|
Action string
|
||
|
Args []string
|
||
|
Port int
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
var c Command
|
||
|
flag.StringVar(&c.Action, "action", "none", fmt.Sprintf("Available actions: %s", getActionNames()))
|
||
|
flag.IntVar(&c.Port, "port", 3001, "The private admin api port")
|
||
|
flag.Parse()
|
||
|
|
||
|
f, exists := actionMap[c.Action]
|
||
|
if !exists {
|
||
|
println("Unknown action:", c.Action)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
f(c)
|
||
|
}
|