@@ -11,9 +11,8 @@ import (
1111)
1212
1313func (c * TemporalConfigDeleteCommand ) run (cctx * CommandContext , _ []string ) error {
14- opts := loadOptsFromContext (cctx )
15- profileName := envConfigProfileName (cctx )
16- conf , confProfile , err := cliext .LoadProfile (opts , profileName , false )
14+ opts := loadProfileOptsFromContext (cctx , false )
15+ conf , confProfile , err := cliext .LoadProfile (opts )
1716 if err != nil {
1817 return err
1918 }
@@ -23,13 +22,12 @@ func (c *TemporalConfigDeleteCommand) run(cctx *CommandContext, _ []string) erro
2322 }
2423
2524 cctx .Logger .Info ("Writing config file" , "file" , opts .ConfigFilePath )
26- return cliext .WriteConfig (conf , opts )
25+ return cliext .WriteConfig (conf , opts . ConfigFilePath )
2726}
2827
2928func (c * TemporalConfigDeleteProfileCommand ) run (cctx * CommandContext , _ []string ) error {
30- opts := loadOptsFromContext (cctx )
31- profileName := envConfigProfileName (cctx )
32- conf , _ , err := cliext .LoadProfile (opts , profileName , false )
29+ opts := loadProfileOptsFromContext (cctx , false )
30+ conf , _ , err := cliext .LoadProfile (opts )
3331 if err != nil {
3432 return err
3533 }
@@ -39,16 +37,15 @@ func (c *TemporalConfigDeleteProfileCommand) run(cctx *CommandContext, _ []strin
3937 if cctx .RootCommand .Profile == "" {
4038 return fmt .Errorf ("to delete an entire profile, --profile must be provided explicitly" )
4139 }
42- delete (conf .Profiles , profileName )
40+ delete (conf .Profiles , opts . ProfileName )
4341
4442 cctx .Logger .Info ("Writing config file" , "file" , opts .ConfigFilePath )
45- return cliext .WriteConfig (conf , opts )
43+ return cliext .WriteConfig (conf , opts . ConfigFilePath )
4644}
4745
4846func (c * TemporalConfigGetCommand ) run (cctx * CommandContext , _ []string ) error {
49- opts := loadOptsFromContext (cctx )
50- profileName := envConfigProfileName (cctx )
51- conf , confProfile , err := cliext .LoadProfile (opts , profileName , false )
47+ opts := loadProfileOptsFromContext (cctx , false )
48+ conf , confProfile , err := cliext .LoadProfile (opts )
5249 if err != nil {
5350 return err
5451 }
@@ -82,7 +79,7 @@ func (c *TemporalConfigGetCommand) run(cctx *CommandContext, _ []string) error {
8279 } else if err := toml .Unmarshal (b , & tomlConf ); err != nil {
8380 return fmt .Errorf ("failed converting from TOML: %w" , err )
8481 }
85- return cctx .Printer .PrintStructured (tomlConf .Profiles [profileName ], printer.StructuredOptions {})
82+ return cctx .Printer .PrintStructured (tomlConf .Profiles [opts . ProfileName ], printer.StructuredOptions {})
8683 } else {
8784 // Get every property individually as a property-value pair except zero vals
8885 propsMap , err := cliext .ListProperties (confProfile )
@@ -101,8 +98,8 @@ func (c *TemporalConfigGetCommand) run(cctx *CommandContext, _ []string) error {
10198}
10299
103100func (c * TemporalConfigListCommand ) run (cctx * CommandContext , _ []string ) error {
104- opts := loadOptsFromContext (cctx )
105- config , err := cliext .LoadConfig (opts )
101+ configFilePath := configFilePathFromContext (cctx )
102+ config , err := cliext .LoadConfig (configFilePath )
106103 if err != nil {
107104 return err
108105 }
@@ -118,9 +115,8 @@ func (c *TemporalConfigListCommand) run(cctx *CommandContext, _ []string) error
118115}
119116
120117func (c * TemporalConfigSetCommand ) run (cctx * CommandContext , _ []string ) error {
121- opts := loadOptsFromContext (cctx )
122- profileName := envConfigProfileName (cctx )
123- conf , confProfile , err := cliext .LoadProfile (opts , profileName , true )
118+ opts := loadProfileOptsFromContext (cctx , true )
119+ conf , confProfile , err := cliext .LoadProfile (opts )
124120 if err != nil {
125121 return err
126122 }
@@ -130,10 +126,18 @@ func (c *TemporalConfigSetCommand) run(cctx *CommandContext, _ []string) error {
130126 }
131127
132128 cctx .Logger .Info ("Writing config file" , "file" , opts .ConfigFilePath )
133- return cliext .WriteConfig (conf , opts )
129+ return cliext .WriteConfig (conf , opts . ConfigFilePath )
134130}
135131
136- func envConfigProfileName (cctx * CommandContext ) string {
132+ func configFilePathFromContext (cctx * CommandContext ) string {
133+ if cctx .RootCommand .ConfigFile != "" {
134+ return cctx .RootCommand .ConfigFile
135+ }
136+ configFilePath , _ := cctx .Options .EnvLookup .LookupEnv ("TEMPORAL_CONFIG_FILE" )
137+ return configFilePath
138+ }
139+
140+ func profileNameFromContext (cctx * CommandContext ) string {
137141 if cctx .RootCommand .Profile != "" {
138142 return cctx .RootCommand .Profile
139143 } else if p , _ := cctx .Options .EnvLookup .LookupEnv ("TEMPORAL_PROFILE" ); p != "" {
@@ -142,9 +146,10 @@ func envConfigProfileName(cctx *CommandContext) string {
142146 return envconfig .DefaultConfigFileProfile
143147}
144148
145- func loadOptsFromContext (cctx * CommandContext ) cliext.LoadOptions {
146- return cliext.LoadOptions {
147- ConfigFilePath : cctx .RootCommand .ConfigFile ,
148- EnvLookup : cctx .Options .EnvLookup ,
149+ func loadProfileOptsFromContext (cctx * CommandContext , createIfMissing bool ) cliext.LoadProfileOptions {
150+ return cliext.LoadProfileOptions {
151+ ConfigFilePath : configFilePathFromContext (cctx ),
152+ ProfileName : profileNameFromContext (cctx ),
153+ CreateIfMissing : createIfMissing ,
149154 }
150155}
0 commit comments