github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/cmd/swarmctl/config/inspect.go (about) 1 package config 2 3 import ( 4 "errors" 5 "fmt" 6 "os" 7 "text/tabwriter" 8 9 "github.com/docker/swarmkit/api" 10 "github.com/docker/swarmkit/cmd/swarmctl/common" 11 gogotypes "github.com/gogo/protobuf/types" 12 "github.com/spf13/cobra" 13 ) 14 15 func printConfigSummary(config *api.Config) { 16 w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0) 17 defer w.Flush() 18 19 common.FprintfIfNotEmpty(w, "ID\t: %s\n", config.ID) 20 common.FprintfIfNotEmpty(w, "Name\t: %s\n", config.Spec.Annotations.Name) 21 if len(config.Spec.Annotations.Labels) > 0 { 22 fmt.Fprintln(w, "Labels\t") 23 for k, v := range config.Spec.Annotations.Labels { 24 fmt.Fprintf(w, " %s\t: %s\n", k, v) 25 } 26 } 27 28 common.FprintfIfNotEmpty(w, "Created\t: %s\n", gogotypes.TimestampString(config.Meta.CreatedAt)) 29 30 fmt.Print(w, "Payload:\n\n") 31 fmt.Println(w, config.Spec.Data) 32 } 33 34 var ( 35 inspectCmd = &cobra.Command{ 36 Use: "inspect <config ID or name>", 37 Short: "Inspect a config", 38 RunE: func(cmd *cobra.Command, args []string) error { 39 if len(args) != 1 { 40 return errors.New("inspect command takes a single config ID or name") 41 } 42 43 client, err := common.Dial(cmd) 44 if err != nil { 45 return err 46 } 47 48 config, err := getConfig(common.Context(cmd), client, args[0]) 49 if err != nil { 50 return err 51 } 52 53 printConfigSummary(config) 54 return nil 55 }, 56 } 57 )