@@ -48,6 +48,7 @@ type Params struct {
4848 activateDefault * project.Namespaced
4949 showVersion bool
5050 nonInteractive bool
51+ configSettings []string
5152}
5253
5354func newParams () * Params {
@@ -71,13 +72,14 @@ func main() {
7172 exitCode = 1
7273 }
7374
75+ if err := events .WaitForEvents (5 * time .Second , rollbar .Wait , an .Wait , logging .Close ); err != nil {
76+ logging .Warning ("state-installer failed to wait for events: %v" , err )
77+ }
78+
7479 if cfg != nil {
7580 events .Close ("config" , cfg .Close )
7681 }
7782
78- if err := events .WaitForEvents (5 * time .Second , rollbar .Wait , an .Wait , logging .Close ); err != nil {
79- logging .Warning ("state-installer failed to wait for events: %v" , err )
80- }
8183 os .Exit (exitCode )
8284 }()
8385
@@ -194,6 +196,11 @@ func main() {
194196 Value : & params .showVersion ,
195197 },
196198 {Name : "non-interactive" , Shorthand : "n" , Hidden : true , Value : & params .nonInteractive }, // don't prompt
199+ {
200+ Name : "config-set" ,
201+ Description : "Set config values in 'key=value' format, can be specified multiple times" ,
202+ Value : & params .configSettings ,
203+ },
197204 // The remaining flags are for backwards compatibility (ie. we don't want to error out when they're provided)
198205 {Name : "channel" , Hidden : true , Value : & garbageString },
199206 {Name : "bbb" , Shorthand : "b" , Hidden : true , Value : & garbageString },
@@ -328,13 +335,26 @@ func execute(out output.Outputer, cfg *config.Instance, an analytics.Dispatcher,
328335 out .Print (fmt .Sprintf ("State Tool Package Manager is already installed at [NOTICE]%s[/RESET]. To reinstall use the [ACTIONABLE]--force[/RESET] flag." , installPath ))
329336 an .Event (anaConst .CatInstallerFunnel , "already-installed" )
330337 params .isUpdate = true
338+
339+ // Apply config settings even when already installed
340+ if err := applyConfigSettings (cfg , params .configSettings ); err != nil {
341+ return errs .Wrap (err , "Failed to apply config settings" )
342+ }
343+
331344 return postInstallEvents (out , cfg , an , params )
332345 }
333346
334347 if err := installOrUpdateFromLocalSource (out , cfg , an , payloadPath , params ); err != nil {
335348 return err
336349 }
337350 storeInstallSource (params .sourceInstaller )
351+
352+ // Apply config settings after installation but before post-install events
353+ // This ensures the State Tool's config is properly set up
354+ if err := applyConfigSettings (cfg , params .configSettings ); err != nil {
355+ return errs .Wrap (err , "Failed to apply config settings" )
356+ }
357+
338358 return postInstallEvents (out , cfg , an , params )
339359}
340360
@@ -501,3 +521,44 @@ func assertCompatibility() error {
501521
502522 return nil
503523}
524+
525+ func applyConfigSettings (cfg * config.Instance , configSettings []string ) error {
526+ for _ , setting := range configSettings {
527+ setting = strings .TrimSpace (setting )
528+ if setting == "" {
529+ continue // Skip empty settings
530+ }
531+ if err := applyConfigSetting (cfg , setting ); err != nil {
532+ return errs .Wrap (err , "Failed to apply config setting: %s" , setting )
533+ }
534+ }
535+ return nil
536+ }
537+
538+ func applyConfigSetting (cfg * config.Instance , setting string ) error {
539+ var key , valueStr string
540+
541+ if strings .Contains (setting , "=" ) {
542+ parts := strings .SplitN (setting , "=" , 2 )
543+ if len (parts ) == 2 {
544+ key = strings .TrimSpace (parts [0 ])
545+ valueStr = strings .TrimSpace (parts [1 ])
546+ }
547+ }
548+
549+ if key == "" || valueStr == "" {
550+ return locale .NewInputError ("err_config_invalid_format" , "Config setting must be in 'key=value' format: {{.V0}}" , setting )
551+ }
552+
553+ // Store the raw string value without type validation since config options
554+ // are not yet registered in the installer context
555+ err := cfg .Set (key , valueStr )
556+ if err != nil {
557+ // Log the error but don't fail the installation for config issues
558+ logging .Warning ("Could not set config value %s=%s: %s" , key , valueStr , errs .JoinMessage (err ))
559+ return locale .WrapError (err , "err_config_set" , "Could not set value {{.V0}} for key {{.V1}}" , valueStr , key )
560+ }
561+
562+ logging .Debug ("Config setting applied: %s=%s" , key , valueStr )
563+ return nil
564+ }
0 commit comments