Skip to content

Commit

Permalink
fix: Print the long options of the required flags missing
Browse files Browse the repository at this point in the history
The error message collected by 'checkRequiredFlags()' now sets the name of the flags
to the long option given in the 'Name: <somecommand>' field.

This change is introduced to fix up an error where printing the error in the
case of a missing required flag looks like:

```
Required flags " n,  t" not set
```

Whilst the expected behaviour is:

```
Required flags "<long-name1>, <long-name2>" not set
```

Signed-off-by: Ole Petter <ole.orhagen@northern.tech>
  • Loading branch information
Ole Petter committed May 2, 2020
1 parent f842187 commit ee2fae6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,12 @@ func checkRequiredFlags(flags []Flag, context *Context) requiredFlagsErr {
var flagPresent bool
var flagName string
for _, key := range strings.Split(f.GetName(), ",") {
key = strings.TrimSpace(key)
if len(key) > 1 {
flagName = key
}

if context.IsSet(strings.TrimSpace(key)) {
if context.IsSet(key) {
flagPresent = true
}
}
Expand Down

0 comments on commit ee2fae6

Please sign in to comment.