diff --git a/cmd/root.go b/cmd/root.go index af6b5a5..489e0fb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,19 +1,18 @@ +/* +Copyright © 2024 NAME HERE +*/ package cmd import ( "fmt" "os" - "os/exec" "path/filepath" - "strings" - "github.com/pterm/pterm" "github.com/spf13/cobra" "github.com/spf13/viper" ) var cfgFile string -var endpoint string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ @@ -22,9 +21,9 @@ var rootCmd = &cobra.Command{ Long: `cfctl controls the SpaceONE services. Find more information at: https://docs.spaceone.megazone.io/cfctl`, - Run: func(cmd *cobra.Command, args []string) { - runEvans() - }, + // Uncomment the following line if your bare application + // has an action associated with it: + // Run: func(cmd *cobra.Command, args []string) { }, } // Execute adds all child commands to the root command and sets flags appropriately. @@ -32,7 +31,6 @@ var rootCmd = &cobra.Command{ func Execute() { err := rootCmd.Execute() if err != nil { - pterm.Error.Println("Error executing root command:", err) os.Exit(1) } } @@ -45,8 +43,6 @@ func init() { // will be global for your application. rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.spaceone/cfctl.yaml)") - rootCmd.PersistentFlags().StringVarP(&endpoint, "endpoint", "e", "", "endpoint to use for the command (e.g., identity, inventory)") - rootCmd.MarkPersistentFlagRequired("endpoint") // Cobra also supports local flags, which will only run // when this action is called directly. @@ -73,43 +69,6 @@ func initConfig() { // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { - pterm.Info.Println("Using config file:", viper.ConfigFileUsed()) - } else { - pterm.Warning.Println("No valid config file found.") - } -} - -// runEvans executes the Evans command with the required parameters. -func runEvans() { - token := viper.GetString("token") - if token == "" { - pterm.Error.Println("Error: token not found in config file") - os.Exit(1) - } - - // Find the specified endpoint - var host string - endpoints := viper.GetStringMapString("endpoints") - if endpointURL, exists := endpoints[endpoint]; exists { - parts := strings.Split(endpointURL, "//") - if len(parts) > 1 { - host = strings.Split(parts[1], ":")[0] - } - } - - if host == "" { - pterm.Error.Printf("Error: endpoint '%s' not found or invalid in config file\n", endpoint) - os.Exit(1) - } - - cmd := exec.Command("evans", "--reflection", "repl", "-p", "443", "--tls", "--header", fmt.Sprintf("token=%s", token), "--host", host) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Stdin = os.Stdin - - err := cmd.Run() - if err != nil { - pterm.Error.Printf("Error running Evans: %v\n", err) - os.Exit(1) + fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } }