Cover more parser cases

This commit is contained in:
Josh Deprez 2024-09-27 11:56:06 +10:00
parent 220af9b306
commit 2c99912a8a

View file

@ -37,10 +37,16 @@ func mainImpl() error {
if err != nil { if err != nil {
return fmt.Errorf("parsing --sense-resistor: %w", err) return fmt.Errorf("parsing --sense-resistor: %w", err)
} }
if resistor <= 0 {
return fmt.Errorf("--sense-resistor must be positive")
}
current, err := parseNanoSI[physic.ElectricCurrent](*maxCurrent) current, err := parseNanoSI[physic.ElectricCurrent](*maxCurrent)
if err != nil { if err != nil {
return fmt.Errorf("parsing --max-current: %w", err) return fmt.Errorf("parsing --max-current: %w", err)
} }
if current <= 0 {
return fmt.Errorf("--max-current must be positive")
}
if _, err := host.Init(); err != nil { if _, err := host.Init(); err != nil {
return err return err
@ -106,7 +112,9 @@ func parseNanoSI[U ~int64](s string) (U, error) {
case 2: case 2:
value *= 1_000_000_000 value *= 1_000_000_000
case 3: case 3:
switch submatches[2] { switch suffix := submatches[2]; suffix {
case "":
value *= 1_000_000_000
case "m": case "m":
value *= 1_000_000 value *= 1_000_000
case "mu", "µ": case "mu", "µ":
@ -114,7 +122,7 @@ func parseNanoSI[U ~int64](s string) (U, error) {
case "n": case "n":
value *= 1 value *= 1
default: default:
return 0, fmt.Errorf("invalid suffix %q", suffix)
} }
} }
return value, nil return value, nil