@@ -32,7 +32,19 @@ func main() {
3232
3333 cancel ()
3434 }()
35- cfg := & config.Config {}
35+
36+ // Initialize config first
37+ if err := config .Init (); err != nil {
38+ fmt .Fprintf (os .Stderr , "Error initializing config: %v\n " , err )
39+ os .Exit (1 )
40+ }
41+
42+ // Get the loaded config
43+ cfg , err := config .Get ()
44+ if err != nil {
45+ fmt .Fprintf (os .Stderr , "Error loading config: %v\n " , err )
46+ os .Exit (1 )
47+ }
3648
3749 rootCmd := & cobra.Command {
3850 Use : "kagent" ,
@@ -43,11 +55,12 @@ func main() {
4355 },
4456 }
4557
46- rootCmd .PersistentFlags ().StringVar (& cfg .KAgentURL , "kagent-url" , "http://localhost:8083" , "KAgent URL" )
47- rootCmd .PersistentFlags ().StringVarP (& cfg .Namespace , "namespace" , "n" , "kagent" , "Namespace" )
48- rootCmd .PersistentFlags ().StringVarP (& cfg .OutputFormat , "output-format" , "o" , "table" , "Output format" )
49- rootCmd .PersistentFlags ().BoolVarP (& cfg .Verbose , "verbose" , "v" , false , "Verbose output" )
50- rootCmd .PersistentFlags ().DurationVar (& cfg .Timeout , "timeout" , 300 * time .Second , "Timeout" )
58+ rootCmd .PersistentFlags ().StringVar (& cfg .KAgentURL , "kagent-url" , cfg .KAgentURL , "KAgent URL" )
59+ rootCmd .PersistentFlags ().StringVarP (& cfg .Namespace , "namespace" , "n" , cfg .Namespace , "Namespace" )
60+ rootCmd .PersistentFlags ().StringVarP (& cfg .OutputFormat , "output-format" , "o" , cfg .OutputFormat , "Output format" )
61+ rootCmd .PersistentFlags ().BoolVarP (& cfg .Verbose , "verbose" , "v" , cfg .Verbose , "Verbose output" )
62+ rootCmd .PersistentFlags ().DurationVar (& cfg .Timeout , "timeout" , cfg .Timeout , "Timeout" )
63+
5164 installCfg := & cli.InstallCfg {
5265 Config : cfg ,
5366 }
@@ -329,12 +342,6 @@ Examples:
329342
330343 rootCmd .AddCommand (installCmd , uninstallCmd , invokeCmd , bugReportCmd , versionCmd , dashboardCmd , getCmd , initCmd , buildCmd , deployCmd , mcp .NewMCPCmd ())
331344
332- // Initialize config
333- if err := config .Init (); err != nil {
334- fmt .Fprintf (os .Stderr , "Error initializing config: %v\n " , err )
335- os .Exit (1 )
336- }
337-
338345 if err := rootCmd .ExecuteContext (ctx ); err != nil {
339346 fmt .Fprintf (os .Stderr , "Error: %v\n " , err )
340347
0 commit comments