diff --git a/cmd/byctl/ls.go b/cmd/byctl/ls.go index f32c85f..75727fd 100644 --- a/cmd/byctl/ls.go +++ b/cmd/byctl/ls.go @@ -5,6 +5,7 @@ import ( "path/filepath" "time" + "github.com/docker/go-units" "github.com/urfave/cli/v2" "go.uber.org/zap" @@ -14,8 +15,9 @@ import ( ) const ( - lsFlagLongName = "l" - lsFlagFormat = "format" + lsFlagLongName = "l" + lsFlagFormat = "format" + lsFlagSummarize = "summarize" ) var lsFlags = []cli.Flag{ @@ -27,6 +29,10 @@ var lsFlags = []cli.Flag{ Name: lsFlagFormat, Usage: "across long -l", }, + &cli.BoolFlag{ + Name: lsFlagSummarize, + Usage: "display summary information", + }, } var lsCmd = &cli.Command{ @@ -70,6 +76,8 @@ var lsCmd = &cli.Command{ } isFirst := true + var totalNum int + var totalSize int64 for v := range ch { if v.Error != nil { @@ -84,9 +92,18 @@ var lsCmd = &cli.Command{ if isFirst { isFirst = false } + + totalNum += 1 + totalSize += oa.size } // End of line fmt.Print("\n") + + // display summary information + if c.Bool(lsFlagSummarize) { + fmt.Printf("\n%14s %d\n", "Total Objects:", totalNum) + fmt.Printf("%14s %s\n", "Total Size:", units.BytesSize(float64(totalSize))) + } return }, } @@ -118,7 +135,7 @@ func (oa objectAttr) shortFormat(isFirst bool) string { if isFirst { return oa.name } - return oa.name + " " + return " " + oa.name } func (oa objectAttr) longFormat(isFirst bool) string {