init application routines
This commit is contained in:
+1
-11
@@ -2,8 +2,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -20,10 +18,7 @@ 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(log *slog.Logger) {
|
||||
ctx := context.WithValue(context.Background(), loggerKey{}, log)
|
||||
rootCmd.SetContext(ctx)
|
||||
|
||||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
@@ -31,11 +26,6 @@ func Execute(log *slog.Logger) {
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initApplication)
|
||||
|
||||
rootCmd.Flags().StringP("out", "o", "", "output file")
|
||||
rootCmd.Flags().StringP("session", "s", "", "output session info to file")
|
||||
}
|
||||
|
||||
func initApplication() {
|
||||
}
|
||||
|
||||
+3
-8
@@ -1,21 +1,16 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"esdi/tui"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"esdi/tui"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func tuiCmdAction(cmd *cobra.Command, args []string) {
|
||||
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)
|
||||
err := tui.Run(slog.Default())
|
||||
if err != nil {
|
||||
fmt.Printf("Error running TUI: %s\n", err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user