@@ -36,7 +36,7 @@ func DefaultCommandValidateFunc() CommandValidateFunc {
36
36
return err
37
37
}
38
38
39
- validateDeprecated (ctx , cmd )
39
+ validateDeprecated (ctx , cmd , cmdArgs , rawArgs )
40
40
return nil
41
41
}
42
42
}
@@ -113,11 +113,26 @@ func validateNoConflict(cmd *Command, rawArgs args.RawArgs) error {
113
113
}
114
114
115
115
// validateDeprecated print a warning message if a deprecated argument is used
116
- func validateDeprecated (ctx context.Context , cmd * Command ) {
116
+ func validateDeprecated (ctx context.Context , cmd * Command , cmdArgs interface {}, rawArgs args. RawArgs ) {
117
117
deprecatedArgs := cmd .ArgSpecs .GetDeprecated (true )
118
- for _ , argSpec := range deprecatedArgs {
119
- helpCmd := cmd .GetCommandLine (extractMeta (ctx ).BinaryName ) + " --help"
120
- ExtractLogger (ctx ).Warningf ("The argument '%s' is deprecated, more info with: %s\n " , argSpec .Name , helpCmd )
118
+ for _ , arg := range deprecatedArgs {
119
+ fieldName := strcase .ToPublicGoName (arg .Name )
120
+ fieldValues , err := getValuesForFieldByName (reflect .ValueOf (cmdArgs ), strings .Split (fieldName , "." ))
121
+ if err != nil {
122
+ validationErr := fmt .Errorf ("could not validate arg value for '%v': invalid field name '%v': %v" , arg .Name , fieldName , err .Error ())
123
+ if ! arg .Required {
124
+ logger .Infof (validationErr .Error ())
125
+ continue
126
+ }
127
+ panic (validationErr )
128
+ }
129
+
130
+ for i := range fieldValues {
131
+ if rawArgs .ExistsArgByName (strings .Replace (arg .Name , "{index}" , strconv .Itoa (i ), 1 )) {
132
+ helpCmd := cmd .GetCommandLine (extractMeta (ctx ).BinaryName ) + " --help"
133
+ ExtractLogger (ctx ).Warningf ("The argument '%s' is deprecated, more info with: %s\n " , arg .Name , helpCmd )
134
+ }
135
+ }
121
136
}
122
137
}
123
138
0 commit comments