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 {
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)
if err != nil {
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 {
return err
@ -106,7 +112,9 @@ func parseNanoSI[U ~int64](s string) (U, error) {
case 2:
value *= 1_000_000_000
case 3:
switch submatches[2] {
switch suffix := submatches[2]; suffix {
case "":
value *= 1_000_000_000
case "m":
value *= 1_000_000
case "mu", "µ":
@ -114,7 +122,7 @@ func parseNanoSI[U ~int64](s string) (U, error) {
case "n":
value *= 1
default:
return 0, fmt.Errorf("invalid suffix %q", suffix)
}
}
return value, nil