Revert " Add community, edition and upgrade commands"

This reverts commit 4b2c678fa3.
This commit is contained in:
M. Mert Yildiran 2023-01-31 00:01:55 +03:00
parent fe2423e9d9
commit 79cc2e70b6
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
6 changed files with 5 additions and 107 deletions

View File

@ -1,37 +0,0 @@
package cmd
import (
"fmt"
"strings"
"github.com/kubeshark/kubeshark/config"
"github.com/kubeshark/kubeshark/misc"
"github.com/kubeshark/kubeshark/utils"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
var communityCmd = &cobra.Command{
Use: "community",
Short: fmt.Sprintf("Use %s Community Edition. (default)", misc.Software),
RunE: func(cmd *cobra.Command, args []string) error {
edition := "community"
config.Config.Edition = edition
if err := config.WriteConfig(&config.Config); err != nil {
log.Error().Err(err).Msg("Failed writing config.")
return nil
}
log.Info().Msgf("%s edition has been set to: %s", misc.Software, strings.Title(edition))
log.Warn().
Str("command", fmt.Sprintf("%s tap", misc.Program)).
Msg(fmt.Sprintf(utils.Yellow, "Now you can run:"))
return nil
},
}
func init() {
rootCmd.AddCommand(communityCmd)
}

View File

@ -36,7 +36,7 @@ var configCmd = &cobra.Command{
return nil
}
log.Debug().Str("template", template).Msg("Printing template config...")
log.Debug().Str("template", template).Msg("Writing template config...")
fmt.Printf("%v", template)
}

View File

@ -1,23 +0,0 @@
package cmd
import (
"fmt"
"strings"
"github.com/kubeshark/kubeshark/config"
"github.com/kubeshark/kubeshark/misc"
"github.com/spf13/cobra"
)
var editionCmd = &cobra.Command{
Use: "edition",
Short: fmt.Sprintf("Print the current edition of %s.", misc.Software),
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println(strings.Title(config.Config.Edition))
return nil
},
}
func init() {
rootCmd.AddCommand(editionCmd)
}

View File

@ -1,37 +0,0 @@
package cmd
import (
"fmt"
"strings"
"github.com/kubeshark/kubeshark/config"
"github.com/kubeshark/kubeshark/misc"
"github.com/kubeshark/kubeshark/utils"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
)
var upgradeCmd = &cobra.Command{
Use: "upgrade",
Short: fmt.Sprintf("Use %s Pro Edition.", misc.Software),
RunE: func(cmd *cobra.Command, args []string) error {
edition := "pro"
config.Config.Edition = edition
if err := config.WriteConfig(&config.Config); err != nil {
log.Error().Err(err).Msg("Failed writing config.")
return nil
}
log.Info().Msgf("%s edition has been set to: %s", misc.Software, strings.Title(edition))
log.Warn().
Str("command", fmt.Sprintf("%s tap", misc.Program)).
Msg(fmt.Sprintf(utils.Yellow, "Now you can run:"))
return nil
},
}
func init() {
rootCmd.AddCommand(upgradeCmd)
}

View File

@ -48,9 +48,7 @@ func InitConfig(cmd *cobra.Command) error {
return nil
}
if cmd.Use != "edition" {
go version.CheckNewerVersion()
}
go version.CheckNewerVersion()
Config = CreateDefaultConfig()
cmdName = cmd.Name()
@ -61,7 +59,7 @@ func InitConfig(cmd *cobra.Command) error {
configFilePathFlag := cmd.Flags().Lookup(ConfigFilePathCommandName)
configFilePath := configFilePathFlag.Value.String()
if err := loadConfigFile(configFilePath, &Config, cmd.Use != "edition"); err != nil {
if err := loadConfigFile(configFilePath, &Config); err != nil {
if configFilePathFlag.Changed || !os.IsNotExist(err) {
return fmt.Errorf("invalid config, %w\n"+
"you can regenerate the file by removing it (%v) and using `kubeshark config -r`", err, configFilePath)
@ -101,7 +99,7 @@ func WriteConfig(config *ConfigStruct) error {
return nil
}
func loadConfigFile(configFilePath string, config *ConfigStruct, logPath bool) error {
func loadConfigFile(configFilePath string, config *ConfigStruct) error {
reader, openErr := os.Open(configFilePath)
if openErr != nil {
return openErr
@ -116,9 +114,7 @@ func loadConfigFile(configFilePath string, config *ConfigStruct, logPath bool) e
return err
}
if logPath {
log.Info().Str("path", configFilePath).Msg("Found config file!")
}
log.Info().Str("path", configFilePath).Msg("Found config file!")
return nil
}

View File

@ -35,7 +35,6 @@ type ConfigStruct struct {
DumpLogs bool `yaml:"dumplogs" default:"false"`
ConfigFilePath string `yaml:"configpath,omitempty" readonly:""`
HeadlessMode bool `yaml:"headless" default:"false"`
Edition string `yaml:"edition" default:"community"`
}
func (config *ConfigStruct) SetDefaults() {