MCPcopy Create free account
hub / github.com/containerd/nerdctl / versionAction

Function versionAction

cmd/nerdctl/version.go:54–117  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

52}
53
54func versionAction(cmd *cobra.Command, args []string) error {
55 var w io.Writer = os.Stdout
56 var tmpl *template.Template
57 globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
58 if err != nil {
59 return err
60 }
61 format, err := cmd.Flags().GetString("format")
62 if err != nil {
63 return err
64 }
65 if format != "" {
66 var err error
67 tmpl, err = formatter.ParseTemplate(format)
68 if err != nil {
69 return err
70 }
71 }
72
73 address := globalOptions.Address
74 // rootless `nerdctl version` runs in the host namespaces, so the address is different
75 if rootlessutil.IsRootless() {
76 address, err = rootlessutil.RootlessContainredSockAddress()
77 if err != nil {
78 log.L.WithError(err).Warning("failed to inspect the rootless containerd socket address")
79 address = ""
80 }
81 }
82
83 v, vErr := versionInfo(cmd, globalOptions.Namespace, address)
84 if tmpl != nil {
85 var b bytes.Buffer
86 if err := tmpl.Execute(&b, v); err != nil {
87 return err
88 }
89 if _, err := fmt.Fprintln(w, b.String()); err != nil {
90 return err
91 }
92 } else {
93 fmt.Fprintln(w, "Client:")
94 fmt.Fprintf(w, " Version:\t%s\n", v.Client.Version)
95 fmt.Fprintf(w, " OS/Arch:\t%s/%s\n", v.Client.Os, v.Client.Arch)
96 fmt.Fprintf(w, " Git commit:\t%s\n", v.Client.GitCommit)
97 for _, compo := range v.Client.Components {
98 fmt.Fprintf(w, " %s:\n", compo.Name)
99 fmt.Fprintf(w, " Version:\t%s\n", compo.Version)
100 for detailK, detailV := range compo.Details {
101 fmt.Fprintf(w, " %s:\t%s\n", detailK, detailV)
102 }
103 }
104 if v.Server != nil {
105 fmt.Fprintln(w)
106 fmt.Fprintln(w, "Server:")
107 for _, compo := range v.Server.Components {
108 fmt.Fprintf(w, " %s:\n", compo.Name)
109 fmt.Fprintf(w, " Version:\t%s\n", compo.Version)
110 for detailK, detailV := range compo.Details {
111 fmt.Fprintf(w, " %s:\t%s\n", detailK, detailV)

Callers

nothing calls this directly

Calls 6

ProcessRootCmdFlagsFunction · 0.92
ParseTemplateFunction · 0.92
IsRootlessFunction · 0.92
versionInfoFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…