talos/internal/app/osctl/cmd/version.go
Andrew Rynhard 4d5350ec41
feat: add config flag to osctl (#413)
Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
2019-02-23 14:33:37 -08:00

56 lines
1.2 KiB
Go

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package cmd
import (
"fmt"
"os"
"github.com/autonomy/talos/internal/app/osctl/internal/client"
"github.com/autonomy/talos/internal/pkg/constants"
"github.com/autonomy/talos/internal/pkg/version"
"github.com/spf13/cobra"
)
var (
shortVersion bool
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if shortVersion {
version.PrintShortVersion()
} else {
if err := version.PrintLongVersion(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
creds, err := client.NewDefaultClientCredentials(talosconfig)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
c, err := client.NewClient(constants.OsdPort, creds)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := c.Version(); err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
func init() {
versionCmd.Flags().BoolVar(&shortVersion, "short", false, "Print the short version")
rootCmd.AddCommand(versionCmd)
}