Skip to content

Commit

Permalink
Merge pull request #276 from zanvd/make-placeholder-output-consistent
Browse files Browse the repository at this point in the history
Make field name output consistent when using placeholders
  • Loading branch information
alexflint authored Dec 11, 2024
2 parents 438bbff + a7ee83c commit f218789
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,13 +746,13 @@ func (p *Parser) process(args []string) error {
if spec.cardinality == multiple {
err := setSliceOrMap(p.val(spec.dest), positionals, true)
if err != nil {
return fmt.Errorf("error processing %s: %v", spec.field.Name, err)
return fmt.Errorf("error processing %s: %v", spec.placeholder, err)
}
positionals = nil
} else {
err := scalar.ParseValue(p.val(spec.dest), positionals[0])
if err != nil {
return fmt.Errorf("error processing %s: %v", spec.field.Name, err)
return fmt.Errorf("error processing %s: %v", spec.placeholder, err)
}
positionals = positionals[1:]
}
Expand All @@ -767,18 +767,13 @@ func (p *Parser) process(args []string) error {
continue
}

name := strings.ToLower(spec.field.Name)
if spec.long != "" && !spec.positional {
name = "--" + spec.long
}

if spec.required {
if spec.short == "" && spec.long == "" {
msg := fmt.Sprintf("environment variable %s is required", spec.env)
return errors.New(msg)
}

msg := fmt.Sprintf("%s is required", name)
msg := fmt.Sprintf("%s is required", spec.placeholder)
if spec.env != "" {
msg += " (or environment variable " + spec.env + ")"
}
Expand Down

0 comments on commit f218789

Please sign in to comment.