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 1, 2020
1 parent 053ba9d commit 9debc2b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions 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(), ",") {
if len(key) > 1 {
flagName = key
_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 9debc2b

Please sign in to comment.