@@ -117,8 +117,10 @@ func ParseCLI(args []string) (string, *CLIOptions, func(), error) {
117117 kongOpts := []kong.Option {kong.Vars {"version" : Version }}
118118
119119 // load default options
120+ var defaultOpt * Option
120121 if optionFilePath != "" {
121- defaultOpt , err := loadDefinitionFile [Option ](nil , optionFilePath , nil )
122+ var err error
123+ defaultOpt , err = loadDefinitionFile [Option ](nil , optionFilePath , nil )
122124 if err != nil {
123125 return "" , nil , nil , fmt .Errorf ("failed to load option file: %w" , err )
124126 }
@@ -148,6 +150,17 @@ func ParseCLI(args []string) (string, *CLIOptions, func(), error) {
148150 }
149151 opts .Envfile = lo .Uniq (envfiles ) // envfiles are parsed before, so it's safe to overwrite
150152
153+ // Merge ext_str and ext_code from option file with CLI args
154+ // CLI args take precedence over option file values
155+ if defaultOpt != nil {
156+ if defaultOpt .ExtStr != nil || opts .ExtStr != nil {
157+ opts .ExtStr = lo .Assign (defaultOpt .ExtStr , opts .ExtStr )
158+ }
159+ if defaultOpt .ExtCode != nil || opts .ExtCode != nil {
160+ opts .ExtCode = lo .Assign (defaultOpt .ExtCode , opts .ExtCode )
161+ }
162+ }
163+
151164 sub := strings .Fields (c .Command ())[0 ]
152165 return sub , & opts , func () { c .PrintUsage (true ) }, nil
153166}
0 commit comments