github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/cmd/snap/cmd_version.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2016 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package main 21 22 import ( 23 "fmt" 24 25 "github.com/jessevdk/go-flags" 26 27 "github.com/snapcore/snapd/client" 28 "github.com/snapcore/snapd/i18n" 29 "github.com/snapcore/snapd/snapdtool" 30 ) 31 32 var shortVersionHelp = i18n.G("Show version details") 33 var longVersionHelp = i18n.G(` 34 The version command displays the versions of the running client, server, 35 and operating system. 36 `) 37 38 type cmdVersion struct { 39 clientMixin 40 } 41 42 func init() { 43 addCommand("version", shortVersionHelp, longVersionHelp, func() flags.Commander { return &cmdVersion{} }, nil, nil) 44 } 45 46 func (cmd cmdVersion) Execute(args []string) error { 47 if len(args) > 0 { 48 return ErrExtraArgs 49 } 50 51 return printVersions(cmd.client) 52 } 53 54 func printVersions(cli *client.Client) error { 55 sv := serverVersion(cli) 56 w := tabWriter() 57 58 fmt.Fprintf(w, "snap\t%s\n", snapdtool.Version) 59 fmt.Fprintf(w, "snapd\t%s\n", sv.Version) 60 fmt.Fprintf(w, "series\t%s\n", sv.Series) 61 if sv.OnClassic { 62 if sv.OSVersionID == "" { 63 sv.OSVersionID = "-" 64 } 65 fmt.Fprintf(w, "%s\t%s\n", sv.OSID, sv.OSVersionID) 66 } 67 if sv.KernelVersion != "" { 68 fmt.Fprintf(w, "kernel\t%s\n", sv.KernelVersion) 69 } 70 71 w.Flush() 72 73 return nil 74 }