model,cli,docs: medium-effort polish for v0.1.0
* model.ParseSize / FormatSizeBytes: pinned with table tests in
internal/model/types_test.go (TestParseSize 22 cases,
TestFormatSizeBytes 11 cases, TestParseSizeFormatRoundTrip 7
boundaries). Fixed the long-suffix regression: "4GiB", "512MiB",
"4KiB" now parse correctly (parser strips trailing IB before
inspecting the unit byte). Pinned current behaviour for
no-suffix input ("1024" treated as MiB) and FormatSizeBytes(0).
commands_image.go --size flag-help updated to show 4GiB now
that the parser accepts it.
* vm ports --json: matches the JSON-vs-table inconsistency between
vm stats (always JSON) and vm ports (always table). --json on
vm ports flips to the same printJSON path as vm stats. Default
table output unchanged. Other vm subcommands (show, stats,
logs, health, ping) didn't fit the identical pattern; left
alone.
* docs/oci-import.md architecture section moved to a new
docs/oci-import-internals.md (precedent: internal/daemon/
ARCHITECTURE.md). User-facing oci-import.md keeps a one-line
pointer for advanced reading.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4d8dca6b72
commit
d0997fd3b5
6 changed files with 196 additions and 42 deletions
|
|
@ -240,23 +240,26 @@ func ParseSize(raw string) (int64, error) {
|
|||
if raw == "" {
|
||||
return 0, errors.New("size is required")
|
||||
}
|
||||
unit := raw[len(raw)-1]
|
||||
// Strip an optional "IB" suffix so that "GiB", "MiB", "KiB" work the
|
||||
// same as "G", "M", "K" (case-insensitive after ToUpper).
|
||||
number := strings.TrimSuffix(raw, "IB")
|
||||
unit := number[len(number)-1]
|
||||
multiplier := int64(1024 * 1024)
|
||||
number := raw
|
||||
switch unit {
|
||||
case 'K':
|
||||
multiplier = 1024
|
||||
number = raw[:len(raw)-1]
|
||||
number = number[:len(number)-1]
|
||||
case 'M':
|
||||
multiplier = 1024 * 1024
|
||||
number = raw[:len(raw)-1]
|
||||
number = number[:len(number)-1]
|
||||
case 'G':
|
||||
multiplier = 1024 * 1024 * 1024
|
||||
number = raw[:len(raw)-1]
|
||||
number = number[:len(number)-1]
|
||||
default:
|
||||
if unit < '0' || unit > '9' {
|
||||
return 0, fmt.Errorf("unsupported size suffix: %q", string(unit))
|
||||
}
|
||||
number = raw // no suffix stripped — keep original digits-only string
|
||||
}
|
||||
value, err := strconv.ParseInt(number, 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue