github.com/demonoid81/containerd@v1.3.4/cmd/ctr/commands/version/version.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package version 18 19 import ( 20 "fmt" 21 "os" 22 23 "github.com/containerd/containerd/cmd/ctr/commands" 24 "github.com/containerd/containerd/version" 25 "github.com/urfave/cli" 26 ) 27 28 // Command is a cli command to output the client and containerd server version 29 var Command = cli.Command{ 30 Name: "version", 31 Usage: "print the client and server versions", 32 Action: func(context *cli.Context) error { 33 fmt.Println("Client:") 34 fmt.Println(" Version: ", version.Version) 35 fmt.Println(" Revision:", version.Revision) 36 fmt.Println("") 37 client, ctx, cancel, err := commands.NewClient(context) 38 if err != nil { 39 return err 40 } 41 defer cancel() 42 v, err := client.Version(ctx) 43 if err != nil { 44 return err 45 } 46 fmt.Println("Server:") 47 fmt.Println(" Version: ", v.Version) 48 fmt.Println(" Revision:", v.Revision) 49 di, err := client.Server(ctx) 50 if err != nil { 51 return err 52 } 53 fmt.Println(" UUID:", di.UUID) 54 if v.Version != version.Version { 55 fmt.Fprintln(os.Stderr, "WARNING: version mismatch") 56 } 57 if v.Revision != version.Revision { 58 fmt.Fprintln(os.Stderr, "WARNING: revision mismatch") 59 } 60 return nil 61 }, 62 }