feat(cli): add robust box listing filters and sorting
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"warpbox/lib/models"
|
||||
)
|
||||
|
||||
// ── List output ──────────────────────────────────────────────
|
||||
|
||||
func formatBoxSummariesTable(summaries []models.BoxSummary) error {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintln(w, "ID\tFiles\tSize\tCreated\tExpires\tPassword\tOne-Time\tExpired")
|
||||
@@ -53,6 +55,31 @@ func formatBoxSummariesJSON(summaries []models.BoxSummary) error {
|
||||
return enc.Encode(out)
|
||||
}
|
||||
|
||||
// ── View output ──────────────────────────────────────────────
|
||||
|
||||
func formatBoxSummaryJSON(s *models.BoxSummary) error {
|
||||
type summaryOut struct {
|
||||
ID string `json:"id"`
|
||||
FileCount int `json:"file_count"`
|
||||
TotalSize int64 `json:"total_size"`
|
||||
TotalSizeLabel string `json:"total_size_label"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
Expired bool `json:"expired"`
|
||||
OneTimeDownload bool `json:"one_time_download"`
|
||||
PasswordProtected bool `json:"password_protected"`
|
||||
}
|
||||
out := summaryOut{
|
||||
ID: s.ID, FileCount: s.FileCount, TotalSize: s.TotalSize,
|
||||
TotalSizeLabel: s.TotalSizeLabel, CreatedAt: s.CreatedAt,
|
||||
ExpiresAt: s.ExpiresAt, Expired: s.Expired,
|
||||
OneTimeDownload: s.OneTimeDownload, PasswordProtected: s.PasswordProtected,
|
||||
}
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(out)
|
||||
}
|
||||
|
||||
func printBoxSummary(s *models.BoxSummary) {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(w, "ID:\t%s\n", s.ID)
|
||||
@@ -70,6 +97,80 @@ func printBoxSummary(s *models.BoxSummary) {
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
// ── Get output ───────────────────────────────────────────────
|
||||
|
||||
func formatBoxGetJSON(boxID string, manifest models.BoxManifest) error {
|
||||
type getOut struct {
|
||||
BoxID string `json:"box_id"`
|
||||
URL string `json:"url"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
Expired bool `json:"expired"`
|
||||
PasswordProtected bool `json:"password_protected"`
|
||||
OneTimeDownload bool `json:"one_time_download"`
|
||||
RetentionKey string `json:"retention_key,omitempty"`
|
||||
RetentionLabel string `json:"retention_label,omitempty"`
|
||||
}
|
||||
out := getOut{
|
||||
BoxID: boxID, URL: "/box/" + boxID,
|
||||
Expired: boxstore.IsExpired(manifest),
|
||||
}
|
||||
if !manifest.CreatedAt.IsZero() {
|
||||
out.CreatedAt = manifest.CreatedAt
|
||||
}
|
||||
if !manifest.ExpiresAt.IsZero() {
|
||||
out.ExpiresAt = manifest.ExpiresAt
|
||||
}
|
||||
out.PasswordProtected = boxstore.IsPasswordProtected(manifest)
|
||||
out.OneTimeDownload = manifest.OneTimeDownload
|
||||
out.RetentionKey = manifest.RetentionKey
|
||||
out.RetentionLabel = manifest.RetentionLabel
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(out)
|
||||
}
|
||||
|
||||
// ── Change output ────────────────────────────────────────────
|
||||
|
||||
func formatChangeResultJSON(boxID string, manifest models.BoxManifest) error {
|
||||
type changeOut struct {
|
||||
BoxID string `json:"box_id"`
|
||||
Updated bool `json:"updated"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||||
Expired bool `json:"expired"`
|
||||
PasswordProtected bool `json:"password_protected"`
|
||||
OneTimeDownload bool `json:"one_time_download"`
|
||||
DisableZip bool `json:"disable_zip"`
|
||||
RetentionKey string `json:"retention_key,omitempty"`
|
||||
RetentionLabel string `json:"retention_label,omitempty"`
|
||||
RetentionSeconds int64 `json:"retention_seconds,omitempty"`
|
||||
FileCount int `json:"file_count"`
|
||||
}
|
||||
out := changeOut{
|
||||
BoxID: boxID, Updated: true,
|
||||
Expired: boxstore.IsExpired(manifest),
|
||||
PasswordProtected: boxstore.IsPasswordProtected(manifest),
|
||||
OneTimeDownload: manifest.OneTimeDownload,
|
||||
DisableZip: manifest.DisableZip,
|
||||
RetentionKey: manifest.RetentionKey,
|
||||
RetentionLabel: manifest.RetentionLabel,
|
||||
RetentionSeconds: manifest.RetentionSecs,
|
||||
FileCount: len(manifest.Files),
|
||||
}
|
||||
if !manifest.CreatedAt.IsZero() {
|
||||
out.CreatedAt = manifest.CreatedAt
|
||||
}
|
||||
if !manifest.ExpiresAt.IsZero() {
|
||||
out.ExpiresAt = manifest.ExpiresAt
|
||||
}
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
return enc.Encode(out)
|
||||
}
|
||||
|
||||
// ── Retention options ────────────────────────────────────────
|
||||
|
||||
func printRetentionOptions() {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintln(w, "Key\tLabel\tSeconds")
|
||||
|
||||
Reference in New Issue
Block a user