From ed3c50e1f37c1c23d1d6b8ce00696dac754487b8 Mon Sep 17 00:00:00 2001 From: Youngjin Jo Date: Mon, 18 Nov 2024 21:25:26 +0900 Subject: [PATCH] refactor: change available commands to other commands Signed-off-by: Youngjin Jo --- cmd/ai.go | 3 +-- cmd/apiResources.go | 1 - cmd/config.go | 2 -- cmd/exec.go | 19 +++++++++---------- cmd/login.go | 1 - cmd/root.go | 22 ++++++++++++++++------ 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/cmd/ai.go b/cmd/ai.go index 4dc8192..70b0cf3 100644 --- a/cmd/ai.go +++ b/cmd/ai.go @@ -19,7 +19,7 @@ import ( var ( apiToken string configPath = filepath.Join(os.Getenv("HOME"), ".cfctl", "config") - resourceDir = filepath.Join(os.Getenv("HOME"), ".cfctl", "training_data") // 학습 전용 디렉터리 경로 + resourceDir = filepath.Join(os.Getenv("HOME"), ".cfctl", "training_data") ) // aiCmd represents the ai command @@ -266,7 +266,6 @@ func queryAIWithContext(query, contextData string) (string, error) { } func init() { - rootCmd.AddCommand(aiCmd) aiCmd.Flags().String("input", "", "Input text for the AI to process") aiCmd.Flags().BoolP("natural", "n", false, "Enable natural language mode for the AI") aiChatCmd.Flags().StringP("query", "q", "", "Query text for the AI to process") diff --git a/cmd/apiResources.go b/cmd/apiResources.go index aeb0d43..a37add6 100644 --- a/cmd/apiResources.go +++ b/cmd/apiResources.go @@ -471,6 +471,5 @@ func splitIntoLinesWithComma(text string, maxWidth int) []string { } func init() { - rootCmd.AddCommand(apiResourcesCmd) apiResourcesCmd.Flags().StringVarP(&endpoints, "service", "s", "", "Specify the services to connect to, separated by commas (e.g., 'identity', 'identity,inventory')") } diff --git a/cmd/config.go b/cmd/config.go index af80c8c..4dcbb36 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -476,8 +476,6 @@ func parseEnvNameFromURL(urlStr string) (string, error) { } func init() { - rootCmd.AddCommand(configCmd) - // Adding subcommands to configCmd configCmd.AddCommand(configInitCmd) configCmd.AddCommand(envCmd) diff --git a/cmd/exec.go b/cmd/exec.go index c13e328..779163a 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -54,16 +54,6 @@ var execCmd = &cobra.Command{ Run: runExecCommand, } -func init() { - rootCmd.AddCommand(execCmd) - execCmd.Flags().StringArrayVarP(¶meters, "parameter", "p", []string{}, "Input Parameter (-p = -p ...)") - execCmd.Flags().StringVarP(&jsonParameter, "json-parameter", "j", "", "JSON type parameter") - execCmd.Flags().StringVarP(&fileParameter, "file-parameter", "f", "", "YAML file parameter") - execCmd.Flags().StringVarP(&apiVersion, "api-version", "v", "v1", "API Version") - execCmd.Flags().StringVarP(&outputFormat, "output", "o", "yaml", "Output format (yaml, json, table, csv)") - execCmd.Flags().BoolVarP(©ToClipboard, "copy", "c", false, "Copy the output to the clipboard (copies any output format)") -} - func loadConfig() (*Config, error) { configPath := fmt.Sprintf("%s/.cfctl/config.yaml", os.Getenv("HOME")) data, err := os.ReadFile(configPath) @@ -413,3 +403,12 @@ func printCSV(data map[string]interface{}) string { } return "" } + +func init() { + execCmd.Flags().StringArrayVarP(¶meters, "parameter", "p", []string{}, "Input Parameter (-p = -p ...)") + execCmd.Flags().StringVarP(&jsonParameter, "json-parameter", "j", "", "JSON type parameter") + execCmd.Flags().StringVarP(&fileParameter, "file-parameter", "f", "", "YAML file parameter") + execCmd.Flags().StringVarP(&apiVersion, "api-version", "v", "v1", "API Version") + execCmd.Flags().StringVarP(&outputFormat, "output", "o", "yaml", "Output format (yaml, json, table, csv)") + execCmd.Flags().BoolVarP(©ToClipboard, "copy", "c", false, "Copy the output to the clipboard (copies any output format)") +} diff --git a/cmd/login.go b/cmd/login.go index 32af124..db1b5e1 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -604,7 +604,6 @@ func selectScopeOrWorkspace(workspaces []map[string]interface{}) string { } func init() { - rootCmd.AddCommand(loginCmd) loginCmd.Flags().StringVarP(&providedUrl, "url", "u", "", "The URL to use for login (e.g. cfctl login -u https://example.com)") //loginCmd.MarkFlagRequired("url") } diff --git a/cmd/root.go b/cmd/root.go index a78dd22..72c9f19 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -34,11 +34,21 @@ func Execute() { } func init() { - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. + OtherCommands := &cobra.Group{ + ID: "other", + Title: "Other Commands:", + } + rootCmd.AddGroup(OtherCommands) + + rootCmd.AddCommand(aiCmd) + rootCmd.AddCommand(apiResourcesCmd) + rootCmd.AddCommand(configCmd) + rootCmd.AddCommand(execCmd) + rootCmd.AddCommand(loginCmd) - // Cobra also supports local flags, which will only run - // when this action is called directly. - //rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + for _, cmd := range rootCmd.Commands() { + if cmd.Name() != "help" && cmd.Name() != "completion" { + cmd.GroupID = "other" + } + } }