Checkpoint
This commit is contained in:
54 files changed
+6855
-526
No files matched your search
+30
-12
@@ -2,12 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"go.maze.io/harmon"
|
||||
"go.maze.io/harmon/config"
|
||||
@@ -17,14 +17,29 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
configFlag := flag.String("config", "", "configuration file path (default: auto detect)")
|
||||
debugFlag := flag.Bool("debug", false, "enable debug log messages")
|
||||
traceFlag := flag.Bool("trace", false, "enable trace log messages (very noisy!)")
|
||||
flag.Parse()
|
||||
cmd := &cli.Command{
|
||||
Name: "harmon",
|
||||
Usage: "Harmon is a playful music player frontend",
|
||||
Action: runFunc,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{Name: "config", Usage: "configuration file path"},
|
||||
&cli.BoolFlag{Name: "debug", Usage: "enable debug log messages"},
|
||||
&cli.BoolFlag{Name: "trace", Usage: "enable trace log messages (noisy!)"},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
scanCommand,
|
||||
},
|
||||
}
|
||||
|
||||
if *traceFlag {
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func runFunc(ctx context.Context, cmd *cli.Command) error {
|
||||
if cmd.Bool("trace") {
|
||||
logrus.SetLevel(logrus.TraceLevel)
|
||||
} else if *debugFlag {
|
||||
} else if cmd.Bool("debug") {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
|
||||
@@ -34,13 +49,14 @@ func main() {
|
||||
"host_arch": runtime.GOARCH,
|
||||
}).Info("Harmon starting")
|
||||
|
||||
if *configFlag == "" {
|
||||
if *configFlag = findConfigFile(); *configFlag == "" {
|
||||
configFile := cmd.String("config")
|
||||
if configFile == "" {
|
||||
if configFile = findConfigFile(); configFile == "" {
|
||||
logrus.Fatal("could not auto detect configuration file; supply one with -config")
|
||||
}
|
||||
}
|
||||
|
||||
config, err := config.Load(*configFlag)
|
||||
config, err := config.Load(configFile)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Fatal("configuration file contains errors")
|
||||
}
|
||||
@@ -52,7 +68,7 @@ func main() {
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
signals := make(chan os.Signal)
|
||||
signals := make(chan os.Signal, 1)
|
||||
signal.Notify(signals, os.Interrupt)
|
||||
signal.Notify(signals, os.Kill)
|
||||
go func(signals <-chan os.Signal, cancel func()) {
|
||||
@@ -62,6 +78,8 @@ func main() {
|
||||
}(signals, cancel)
|
||||
|
||||
if err = controller.Run(ctx); err != nil && err != context.Canceled {
|
||||
logrus.WithError(err).Fatal("terminating by fatal error")
|
||||
//logrus.WithError(err).Fatal("terminating by fatal error")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user