mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-04 11:58:41 +00:00
🐛 Fix the version
command
This commit is contained in:
parent
f31ad4f9f0
commit
fa0fb62e07
@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/kubeshark/kubeshark/config"
|
||||
"github.com/kubeshark/kubeshark/kubeshark/version"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -32,13 +31,11 @@ func init() {
|
||||
|
||||
rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName))
|
||||
rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName))
|
||||
rootCmd.PersistentFlags().Bool("debug", false, "Enable debug mode.")
|
||||
rootCmd.PersistentFlags().BoolP("debug", "d", false, "Enable debug mode.")
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the tapCmd.
|
||||
func Execute() {
|
||||
go version.CheckNewerVersion()
|
||||
|
||||
cobra.CheckErr(rootCmd.Execute())
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/kubeshark/kubeshark/config/configStructs"
|
||||
"github.com/kubeshark/kubeshark/config"
|
||||
"github.com/kubeshark/kubeshark/kubeshark"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
@ -16,24 +16,20 @@ var versionCmd = &cobra.Command{
|
||||
Short: "Print version info",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
timeStampInt, _ := strconv.ParseInt(kubeshark.BuildTimestamp, 10, 0)
|
||||
if config.DebugMode {
|
||||
log.Info().
|
||||
Str("version", kubeshark.Ver).
|
||||
Str("branch", kubeshark.Branch).
|
||||
Str("commit-hash", kubeshark.GitCommitHash).
|
||||
Time("build-time", time.Unix(timeStampInt, 0)).
|
||||
Send()
|
||||
} else {
|
||||
fmt.Println(kubeshark.Ver)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
||||
defaultVersionConfig := configStructs.VersionConfig{}
|
||||
if err := defaults.Set(&defaultVersionConfig); err != nil {
|
||||
log.Error().Err(err).Send()
|
||||
}
|
||||
|
||||
versionCmd.Flags().BoolP(configStructs.DebugInfoVersionName, "d", defaultVersionConfig.DebugInfo, "Provide all information about version")
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/kubeshark/kubeshark/kubeshark/version"
|
||||
"github.com/kubeshark/kubeshark/utils"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
@ -28,19 +29,27 @@ const (
|
||||
|
||||
var (
|
||||
Config = ConfigStruct{}
|
||||
DebugMode bool
|
||||
cmdName string
|
||||
)
|
||||
|
||||
func InitConfig(cmd *cobra.Command) error {
|
||||
debugMode, err := cmd.Flags().GetBool(DebugFlag)
|
||||
var err error
|
||||
DebugMode, err = cmd.Flags().GetBool(DebugFlag)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg(fmt.Sprintf("Can't recieve '%s' flag", DebugFlag))
|
||||
}
|
||||
|
||||
if debugMode {
|
||||
if DebugMode {
|
||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||
}
|
||||
|
||||
if cmd.Use == "version" {
|
||||
return nil
|
||||
}
|
||||
|
||||
go version.CheckNewerVersion()
|
||||
|
||||
Config.Hub = HubConfig{
|
||||
PortForward{
|
||||
8898,
|
||||
|
@ -59,7 +59,6 @@ type ConfigStruct struct {
|
||||
Front FrontConfig `yaml:"front"`
|
||||
Tap configStructs.TapConfig `yaml:"tap"`
|
||||
Check configStructs.CheckConfig `yaml:"check"`
|
||||
Version configStructs.VersionConfig `yaml:"version"`
|
||||
View configStructs.ViewConfig `yaml:"view"`
|
||||
Logs configStructs.LogsConfig `yaml:"logs"`
|
||||
Config configStructs.ConfigConfig `yaml:"config,omitempty"`
|
||||
|
@ -1,9 +0,0 @@
|
||||
package configStructs
|
||||
|
||||
const (
|
||||
DebugInfoVersionName = "debug"
|
||||
)
|
||||
|
||||
type VersionConfig struct {
|
||||
DebugInfo bool `yaml:"debug" default:"false"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user