The idea is that whenever we encounter a shorthand combination, we search for the first flag in the combination that needs a value (if there are no such flags, then we just go to the next argument). If this flag is the last flag in the shorthand combination, then the value will be expected in the next argument. Otherwise, if the flag is not on the last position of the shorthand combination, the value is expected to be given in the same argument (in this case, we go to the next argument without doing anything).
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.
Fixes: #2188
Note: This PR fixes the same bug in two different code paths (
c.Find()
andc.Traverse()
). They use different helper functions for parsing the arguments, but the fix is based on the same idea. https://github.com/spf13/cobra/blob/78bfc837fe358c750faa7e7f0a8016b300044d58/command.go#L1090-L1094The idea is that whenever we encounter a shorthand combination, we search for the first flag in the combination that needs a value (if there are no such flags, then we just go to the next argument). If this flag is the last flag in the shorthand combination, then the value will be expected in the next argument. Otherwise, if the flag is not on the last position of the shorthand combination, the value is expected to be given in the same argument (in this case, we go to the next argument without doing anything).