File: inspect.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (57 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package config

import (
	"errors"
	"fmt"
	"os"
	"text/tabwriter"

	"github.com/docker/swarmkit/api"
	"github.com/docker/swarmkit/cmd/swarmctl/common"
	gogotypes "github.com/gogo/protobuf/types"
	"github.com/spf13/cobra"
)

func printConfigSummary(config *api.Config) {
	w := tabwriter.NewWriter(os.Stdout, 8, 8, 8, ' ', 0)
	defer w.Flush()

	common.FprintfIfNotEmpty(w, "ID\t: %s\n", config.ID)
	common.FprintfIfNotEmpty(w, "Name\t: %s\n", config.Spec.Annotations.Name)
	if len(config.Spec.Annotations.Labels) > 0 {
		fmt.Fprintln(w, "Labels\t")
		for k, v := range config.Spec.Annotations.Labels {
			fmt.Fprintf(w, "  %s\t: %s\n", k, v)
		}
	}

	common.FprintfIfNotEmpty(w, "Created\t: %s\n", gogotypes.TimestampString(config.Meta.CreatedAt))

	fmt.Print(w, "Payload:\n\n")
	fmt.Println(w, config.Spec.Data)
}

var (
	inspectCmd = &cobra.Command{
		Use:   "inspect <config ID or name>",
		Short: "Inspect a config",
		RunE: func(cmd *cobra.Command, args []string) error {
			if len(args) != 1 {
				return errors.New("inspect command takes a single config ID or name")
			}

			client, err := common.Dial(cmd)
			if err != nil {
				return err
			}

			config, err := getConfig(common.Context(cmd), client, args[0])
			if err != nil {
				return err
			}

			printConfigSummary(config)
			return nil
		},
	}
)