Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"encoding/json"
"fmt"
"os"

"github.com/navilg/k8senv/internal/config"
"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version of K8senv",
// Long: `A longer description that spans multiple lines and likely contains examples
// and usage of using your command. For example:

// Cobra is a CLI library for Go that empowers applications.
// This application is a tool to generate the needed files
// to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
data, err := json.Marshal(config.Version)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("VersionInfo", string(data))
},
}

func init() {
rootCmd.AddCommand(versionCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// versionCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
11 changes: 11 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ package config

import (
"os"
"runtime"
"strings"
)

type VersionInfo struct {
GoVersion string `json:"GoVersion"`
K8senv string `json:"K8senv"`
}

var Version = VersionInfo{
GoVersion: runtime.Version(),
K8senv: "v0.1.2",
}

func GetDotK8senvPath() *string {
pathenv := os.Getenv("PATH")
paths := strings.Split(pathenv, ":")
Expand Down