@@ -15,14 +15,12 @@ import (
1515 "github.com/spf13/cobra"
1616)
1717
18- // App represents the installer application.
18+ // App represents the installer application runtime.
19+ // It holds runtime dependencies and coordinates the execution of commands.
20+ // Application metadata (name, version, etc.) is stored in AppCtx.
1921type App struct {
20- Name string // application name
21- Version string // application version
22- CommitID string // application commit ID
23- Short string // short description
24- Long string // long description
25- ChartFS * chartfs.ChartFS // installer filesystem
22+ AppCtx * api.AppContext // application metadata (single source of truth)
23+ ChartFS * chartfs.ChartFS // installer filesystem
2624
2725 integrations []api.IntegrationModule // supported integrations
2826 integrationManager * integrations.Manager // integrations manager
@@ -47,15 +45,15 @@ func (a *App) Run() error {
4745// setupRootCmd instantiates the Cobra Root command with subcommand, description,
4846// Kubernetes API client instance and more.
4947func (a * App ) setupRootCmd () error {
50- short := a .Short
48+ short := a .AppCtx . Short
5149 if short == "" {
52- short = a .Name + " installer"
50+ short = a .AppCtx . Name + " installer"
5351 }
5452
5553 a .rootCmd = & cobra.Command {
56- Use : a .Name ,
54+ Use : a .AppCtx . Name ,
5755 Short : short ,
58- Long : a .Long ,
56+ Long : a .AppCtx . Long ,
5957 SilenceUsage : true ,
6058 }
6159
@@ -65,7 +63,8 @@ func (a *App) setupRootCmd() error {
6563 // Handle version flag and help.
6664 a .rootCmd .RunE = func (cmd * cobra.Command , args []string ) error {
6765 if a .flags .Version {
68- a .flags .ShowVersion (a .Name , a .Version , a .CommitID )
66+ a .flags .ShowVersion (
67+ a .AppCtx .Name , a .AppCtx .Version , a .AppCtx .CommitID )
6968 return nil
7069 }
7170 return cmd .Help ()
@@ -76,14 +75,14 @@ func (a *App) setupRootCmd() error {
7675 // Loading informed integrations into the manager.
7776 a .integrationManager = integrations .NewManager ()
7877 if err := a .integrationManager .LoadModules (
79- a .Name , logger , a .kube , a .integrations ,
78+ a .AppCtx . Name , logger , a .kube , a .integrations ,
8079 ); err != nil {
8180 return fmt .Errorf ("failed to load modules: %w" , err )
8281 }
8382
8483 // Register standard subcommands.
8584 a .rootCmd .AddCommand (subcmd .NewIntegration (
86- a .Name , logger , a .kube , a .ChartFS , a .integrationManager ,
85+ a .AppCtx , logger , a .kube , a .ChartFS , a .integrationManager ,
8786 ))
8887
8988 // Use default builder if none provided.
@@ -100,32 +99,67 @@ func (a *App) setupRootCmd() error {
10099
101100 // Other subcommands via api.Runner.
102101 subs := []api.SubCommand {
103- subcmd .NewConfig (logger , a .flags , a .ChartFS , a .kube ),
104- subcmd .NewDeploy (logger , a .flags , a .ChartFS , a .kube , a .integrationManager ),
105- subcmd .NewInstaller (a .flags ),
102+ subcmd .NewConfig (
103+ a .AppCtx ,
104+ logger ,
105+ a .flags ,
106+ a .ChartFS ,
107+ a .kube ,
108+ ),
109+ subcmd .NewDeploy (
110+ a .AppCtx ,
111+ logger ,
112+ a .flags ,
113+ a .ChartFS ,
114+ a .kube ,
115+ a .integrationManager ,
116+ ),
117+ subcmd .NewInstaller (
118+ a .AppCtx ,
119+ a .flags ,
120+ ),
106121 subcmd .NewMCPServer (
107- a .Name ,
122+ a .AppCtx ,
108123 a .flags ,
109124 a .ChartFS ,
110125 a .kube ,
111126 a .integrationManager ,
112127 mcpBuilder ,
113128 a .mcpImage ,
114129 ),
115- subcmd .NewTemplate (logger , a .flags , a .ChartFS , a .kube ),
116- subcmd .NewTopology (logger , a .ChartFS , a .kube ),
130+ subcmd .NewTemplate (
131+ a .AppCtx ,
132+ logger ,
133+ a .flags ,
134+ a .ChartFS ,
135+ a .kube ,
136+ ),
137+ subcmd .NewTopology (
138+ a .AppCtx ,
139+ logger ,
140+ a .ChartFS ,
141+ a .kube ,
142+ ),
117143 }
118144 for _ , sub := range subs {
119145 a .rootCmd .AddCommand (api .NewRunner (sub ).Cmd ())
120146 }
121147 return nil
122148}
123149
124- // NewApp creates a new installer application. It automatically sets up the Cobra
125- // Root Command and standard subcommands (Config, Integration, Deploy).
126- func NewApp (name string , cfs * chartfs.ChartFS , opts ... Option ) (* App , error ) {
150+ // NewApp creates a new installer application runtime.
151+ // It automatically sets up the Cobra Root Command and standard subcommands.
152+ //
153+ // The appCtx parameter provides application metadata (name, version, etc.).
154+ // The cfs parameter provides access to the installer filesystem (charts, config).
155+ // Additional runtime options can be passed via functional options.
156+ func NewApp (
157+ appCtx * api.AppContext ,
158+ cfs * chartfs.ChartFS ,
159+ opts ... Option ,
160+ ) (* App , error ) {
127161 app := & App {
128- Name : name ,
162+ AppCtx : appCtx ,
129163 ChartFS : cfs ,
130164 flags : flags .NewFlags (),
131165 }
0 commit comments