Yeah, I kinda gave up, i will fix it later or something I recon
This commit is contained in:
+8
-1
@@ -2,6 +2,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -14,9 +16,14 @@ var rootCmd = &cobra.Command{
|
||||
Long: `Allows the configuration and communication with the dashDisplay`,
|
||||
}
|
||||
|
||||
type loggerKey struct{}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
func Execute(log *slog.Logger) {
|
||||
ctx := context.WithValue(context.Background(), loggerKey{}, log)
|
||||
rootCmd.SetContext(ctx)
|
||||
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
|
||||
+9
-1
@@ -3,14 +3,22 @@ package cmd
|
||||
import (
|
||||
"esdi/tui"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func tuiCmdAction(cmd *cobra.Command, args []string) {
|
||||
err := tui.Run()
|
||||
logger, ok := cmd.Context().Value(loggerKey{}).(*slog.Logger)
|
||||
if !ok {
|
||||
fmt.Printf("Error loading logger from context: %s\n", logger)
|
||||
return
|
||||
}
|
||||
|
||||
err := tui.Run(logger)
|
||||
if err != nil {
|
||||
fmt.Printf("Error running TUI: %s\n", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user