parsePositiveFloat parses a positive float64 option value
( ctx context.Context, o *options.Options, key string, args ...string, )
| 74 | |
| 75 | // parsePositiveFloat parses a positive float64 option value |
| 76 | func (p *Parser) parsePositiveFloat( |
| 77 | ctx context.Context, |
| 78 | o *options.Options, |
| 79 | key string, |
| 80 | args ...string, |
| 81 | ) error { |
| 82 | if err := p.ensureMaxArgs(ctx, key, args, 1); err != nil { |
| 83 | return err |
| 84 | } |
| 85 | |
| 86 | f, err := strconv.ParseFloat(args[0], 64) |
| 87 | if err != nil || f < 0 { |
| 88 | return newInvalidArgumentError(ctx, key, args[0], "positive number or 0") |
| 89 | } |
| 90 | |
| 91 | o.Set(key, f) |
| 92 | |
| 93 | return nil |
| 94 | } |
| 95 | |
| 96 | // parsePositiveNonZeroFloat parses a positive non-zero float64 option value |
| 97 | func (p *Parser) parsePositiveNonZeroFloat( |
no test coverage detected