[server][cli] Print version history in ls

This commit is contained in:
Abhishek Shroff
2025-06-09 00:49:09 +05:30
parent 3d61961fc3
commit 6da29b93b4
10 changed files with 98 additions and 36 deletions

View File

@@ -54,7 +54,8 @@ func FormatSize(size int) string {
for ; sz >= 1000 && si < len(suffix); si, sz = si+1, sz/1024 {
}
if sz >= 10 || si == 0 {
return fmt.Sprintf("%4d%s", int(math.Ceil(sz)), suffix[si])
return strconv.Itoa(int(math.Ceil(sz))) + suffix[si]
// return fmt.Sprintf("%d%s", int(math.Ceil(sz)), suffix[si])
} else {
return fmt.Sprintf("%1.1f%s", sz, suffix[si])
}

View File

@@ -29,7 +29,7 @@ func setupCatCommand() *cobra.Command {
os.Exit(1)
}
v, err := f.FindVersion(r, uuid.Nil)
v, err := f.GetVersion(r, uuid.Nil)
if err != nil {
fmt.Println("cannot find latest version of '" + path + "': " + err.Error())
os.Exit(1)

View File

@@ -85,8 +85,24 @@ to the resource with a particular ID.`,
fmt.Println(common.FormatResourceSummary(c, "", r.Deleted()))
}
} else {
fmt.Println(" Size: " + common.FormatSize(int(r.LatestVersion().Size)))
fmt.Println("SHA-256: " + r.LatestVersion().SHA256[0:12])
fmt.Println(" Size: " + common.FormatSize(int(r.LatestVersion().Size)))
fmt.Println(" SHA-256: " + r.LatestVersion().SHA256[0:12])
versions, err := f.GetAllVersions(r)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Println("Versions: " + strconv.Itoa(len(versions)))
for i, v := range versions {
extra := ""
if i == 0 {
extra += " [current]"
}
if v.Deleted != 0 {
extra += " [deleted]"
}
fmt.Printf("%s %5s %s %s%s\n", v.ID.String(), common.FormatSize(int(v.Size)), v.SHA256[0:12], time.Unix(int64(v.Created), 0).Local().Format(time.RFC1123), extra)
}
}
},
}