mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 10:12:35 +00:00
Added a small utility method to display warnings when parsing command arguments. (#16441)
* Added a small utility method to display warnings when parsing command arguments Will print warning if flag is passed after arguments e.g. vault <command> -a b -c In this example -c will be interpreted as an argument which may be misleading
This commit is contained in:
@@ -292,3 +292,19 @@ func parseFlagFile(raw string) (string, error) {
|
||||
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
func generateFlagWarnings(args []string) string {
|
||||
var trailingFlags []string
|
||||
for _, arg := range args {
|
||||
if strings.HasPrefix(arg, "-") {
|
||||
trailingFlags = append(trailingFlags, arg)
|
||||
}
|
||||
}
|
||||
|
||||
if len(trailingFlags) > 0 {
|
||||
return fmt.Sprintf("Flags must be provided before positional arguments. "+
|
||||
"The following arguments will not be parsed as flags: [%s]", strings.Join(trailingFlags, ","))
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user