瀏覽代碼

use human readable units when listing secrets

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
Evan Hazlett 8 年之前
父節點
當前提交
880e8be1ee
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      cli/command/secret/ls.go

+ 7 - 1
cli/command/secret/ls.go

@@ -4,10 +4,12 @@ import (
 	"context"
 	"context"
 	"fmt"
 	"fmt"
 	"text/tabwriter"
 	"text/tabwriter"
+	"time"
 
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/cli"
 	"github.com/docker/docker/cli"
 	"github.com/docker/docker/cli/command"
 	"github.com/docker/docker/cli/command"
+	"github.com/docker/go-units"
 	"github.com/spf13/cobra"
 	"github.com/spf13/cobra"
 )
 )
 
 
@@ -52,7 +54,11 @@ func runSecretList(dockerCli *command.DockerCli, opts listOptions) error {
 		fmt.Fprintf(w, "\n")
 		fmt.Fprintf(w, "\n")
 
 
 		for _, s := range secrets {
 		for _, s := range secrets {
-			fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%d\n", s.ID, s.Spec.Annotations.Name, s.Meta.CreatedAt, s.Meta.UpdatedAt, s.SecretSize)
+			created := units.HumanDuration(time.Now().UTC().Sub(s.Meta.CreatedAt)) + " ago"
+			updated := units.HumanDuration(time.Now().UTC().Sub(s.Meta.UpdatedAt)) + " ago"
+			size := units.HumanSizeWithPrecision(float64(s.SecretSize), 3)
+
+			fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", s.ID, s.Spec.Annotations.Name, created, updated, size)
 		}
 		}
 	}
 	}