Skip to content

Commit

Permalink
List datasets more info (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell authored Sep 2, 2024
2 parents d24ea15 + d9de7b2 commit 53912fb
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ func DatasetFiles(token string) error {
if err != nil {
return err
}
formatedBytes := func(size int) string {
if !*bytesFormat {
return humanize.Bytes(uint64(size))
}

return strconv.Itoa(size)
}
// Set rather long minimum column widths, so that header matches the rest of the table
fileIDWidth, sizeWidth := 20, 10
fmt.Printf("%-*s \t %-*s \t %s\n", fileIDWidth, "FileID", sizeWidth, "Size", "Path")
Expand All @@ -133,14 +126,37 @@ func DatasetFiles(token string) error {
return nil
}

func formatedBytes(size int) string {
if !*bytesFormat {
return humanize.Bytes(uint64(size))
}

return strconv.Itoa(size)
}

func Datasets(token string) error {
datasets, err := download.GetDatasets(*URL, token)
if err != nil {
return err
}

// Loop through the datasets and list them
for _, dataset := range datasets {
fmt.Printf("%s \n", dataset)
files, err := download.GetFilesInfo(*URL, dataset, "", token)
if err != nil {
return err
}
// Set rather long minimum column widths, so that header matches the rest of the table
fileIDWidth := 40
fmt.Printf("%-*s \t %s \t %s\n", fileIDWidth, "DatasetID", "Files", "Size")
datasetSize := 0
noOfFiles := 0
// Loop through the files and get their sizes
for _, file := range files {
datasetSize += file.DecryptedFileSize
noOfFiles++
}
fmt.Printf("%s \t %d \t %s\n", dataset, noOfFiles, formatedBytes(datasetSize))
}

return nil
Expand Down

0 comments on commit 53912fb

Please sign in to comment.