From 057192cef59bd6496191ce68904a4bcf08668326 Mon Sep 17 00:00:00 2001 From: Manuel Odendahl Date: Sun, 6 Aug 2023 14:51:46 -0400 Subject: [PATCH] :sparkles: Add proper initialization and logging configuration --- cmd/mastoid/main.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cmd/mastoid/main.go b/cmd/mastoid/main.go index b6b88ea..f6c7a43 100644 --- a/cmd/mastoid/main.go +++ b/cmd/mastoid/main.go @@ -2,18 +2,42 @@ package main import ( "fmt" + clay "github.com/go-go-golems/clay/pkg" + "github.com/go-go-golems/glazed/pkg/help" cmds "github.com/go-go-golems/go-go-labs/cmd/mastoid/cmds" - "github.com/go-go-golems/go-go-labs/cmd/mastoid/pkg" "github.com/spf13/cobra" ) var rootCmd = &cobra.Command{ Use: "mastoid", Short: "mastoid is a CLI app to interact with Mastodon", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + // reinitialize the logger because we can now parse --log-level and co + // from the command line flag + err := clay.InitLogger() + cobra.CheckErr(err) + }, +} + +func initRootCmd() (*help.HelpSystem, error) { + helpSystem := help.NewHelpSystem() + helpSystem.SetupCobraRootCommand(rootCmd) + + err := clay.InitViper("mastoid", rootCmd) + if err != nil { + return nil, err + } + err = clay.InitLogger() + if err != nil { + return nil, err + } + + return helpSystem, nil } func main() { - pkg.InitConfig() + _, err := initRootCmd() + cobra.CheckErr(err) cmds.ThreadCmd.Flags().StringP("status-id", "s", "", "Status ID") cmds.ThreadCmd.Flags().BoolP("verbose", "v", false, "Verbose output")