Cover more parser cases
This commit is contained in:
parent
220af9b306
commit
2c99912a8a
1 changed files with 10 additions and 2 deletions
12
exporter.go
12
exporter.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue