From 8f62831b9d1beed6aabcf8549b0bd6a471e5c167 Mon Sep 17 00:00:00 2001 From: AlexSSD7 Date: Wed, 30 Aug 2023 14:53:22 +0100 Subject: [PATCH] Version cmd --- cmd/root.go | 3 +-- cmd/version.go | 17 +++++++++++++++++ constants/linsk.go | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 cmd/version.go create mode 100644 constants/linsk.go diff --git a/cmd/root.go b/cmd/root.go index 67781d5..9eae79c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,8 +33,6 @@ var vmSSHSetupTimeoutFlag uint32 var vmOSUpTimeoutFlag uint32 var dataDirFlag string -// TODO: Version command. - func init() { slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, nil))) @@ -43,6 +41,7 @@ func init() { rootCmd.AddCommand(shellCmd) rootCmd.AddCommand(cleanCmd) rootCmd.AddCommand(buildCmd) + rootCmd.AddCommand(versionCmd) rootCmd.PersistentFlags().BoolVar(&vmDebugFlag, "vm-debug", false, "Enables the VM debug mode. This will open an accessible VM monitor. You can log in with root user and no password.") rootCmd.PersistentFlags().BoolVar(&unrestrictedNetworkingFlag, "vm-unrestricted-networking", false, "Enables unrestricted networking. This will allow the VM to connect to the internet.") diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..c3c53ea --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "fmt" + "runtime" + + "github.com/AlexSSD7/linsk/constants" + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Show Linsk version.", + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("Linsk %v %v/%v %v", constants.Version, runtime.GOOS, runtime.GOARCH, runtime.Version()) + }, +} diff --git a/constants/linsk.go b/constants/linsk.go new file mode 100644 index 0000000..b56cb19 --- /dev/null +++ b/constants/linsk.go @@ -0,0 +1,3 @@ +package constants + +const Version = "v1.0.0"