mirror of
https://github.com/kopia/kopia.git
synced 2026-09-13 05:37:46 -04:00
The --parallel flag was declared with kingpin .IntVar on 12 commands, which accepted negative values and led to a panic at runtime (e.g. `snapshot migrate --parallel=-1`). Declare the --parallel family as uint so kingpin rejects negative input at parse time. The uint->int conversion the callee APIs need is done through a small helper . Add CLI test that asserts the rejection message (a bare failure check passed even without the fix since the commands also fail with no repository connected). Parse via ParseFloat like kingpin's built-in int flag so the only behavior change is rejecting negatives.
14 lines
250 B
Go
14 lines
250 B
Go
package cli
|
|
|
|
import "math"
|
|
|
|
// parallelismAsInt converts --parallel-style flag values from
|
|
// uint to int and clamps returned values at MaxInt32.
|
|
func parallelismAsInt(v uint) int {
|
|
if v > math.MaxInt32 {
|
|
return math.MaxInt32
|
|
}
|
|
|
|
return int(v)
|
|
}
|