From c719d86f2b4cb19662304669c5c9b9aae0037383 Mon Sep 17 00:00:00 2001 From: Sam Tholiya Date: Tue, 24 Dec 2024 12:18:50 +0100 Subject: [PATCH] remove old help code --- cmd/terraform.go | 10 ++++++++- cmd/terraform_commands.go | 7 ++++-- internal/exec/help.go | 46 --------------------------------------- 3 files changed, 14 insertions(+), 49 deletions(-) diff --git a/cmd/terraform.go b/cmd/terraform.go index cee89f77d..9cda9fbf2 100644 --- a/cmd/terraform.go +++ b/cmd/terraform.go @@ -43,7 +43,15 @@ func terraformRun(cmd *cobra.Command, args []string) error { // Exit on help if info.NeedHelp { if info.SubCommand != "" { - fmt.Printf(`Error: Unknkown command %q for %q`+"\n", args[0], cmd.CommandPath()) + suggestions := cmd.SuggestionsFor(args[0]) + if len(suggestions) > 0 { + fmt.Printf("Unknown command: '%s'\n\nDid you mean this?\n", args[0]) + for _, suggestion := range suggestions { + fmt.Printf(" %s\n", suggestion) + } + } else { + fmt.Printf(`Error: Unknkown command %q for %q`+"\n", args[0], cmd.CommandPath()) + } fmt.Printf(`Run '%s --help' for usage`+"\n", cmd.CommandPath()) return fmt.Errorf("unknown command %q for %q", args[0], cmd.CommandPath()) } diff --git a/cmd/terraform_commands.go b/cmd/terraform_commands.go index 4802e7f40..902ee2e31 100644 --- a/cmd/terraform_commands.go +++ b/cmd/terraform_commands.go @@ -253,11 +253,14 @@ func attachTerraformCommands(parentCmd *cobra.Command) { if setFlags, ok := commandMaps[cmd.Use]; ok { setFlags(cmd) } - cmd.Run = func(cmd_ *cobra.Command, args []string) { + cmd.RunE = func(cmd_ *cobra.Command, args []string) error { if len(os.Args) > 3 { args = os.Args[2:] } - parentCmd.Run(parentCmd, args) + if parentCmd.Run != nil { + return parentCmd.RunE(parentCmd, args) + } + return nil } parentCmd.AddCommand(cmd) } diff --git a/internal/exec/help.go b/internal/exec/help.go index 507439ddb..628f09fa0 100644 --- a/internal/exec/help.go +++ b/internal/exec/help.go @@ -29,52 +29,6 @@ func processHelp( u.PrintMessage(" - double-dash '--' can be used to signify the end of the options for Atmos and the start of the additional " + "native arguments and flags for the 'helmfile' commands") } - } else if componentType == "terraform" && command == "clean" { - u.PrintMessage("\n'atmos terraform clean' command deletes the following folders and files from the component's directory:\n\n" + - " - '.terraform' folder\n" + - " - folder that the 'TF_DATA_DIR' ENV var points to\n" + - " - '.terraform.lock.hcl' file\n" + - " - generated varfile for the component in the stack\n" + - " - generated planfile for the component in the stack\n" + - " - generated 'backend.tf.json' file\n" + - " - 'terraform.tfstate.d' folder (if '--everything' flag is used)\n\n" + - "Usage: atmos terraform clean -s \n\n" + - "Use '--everything' flag to also delete the Terraform state files and and directories with confirm message.\n\n" + - "Use --force to forcefully delete Terraform state files and directories for the component.\n\n" + - "- If no component is specified, the command will apply to all components and stacks.\n" + - "- If no stack is specified, the command will apply to all stacks for the specified component.\n" + - "Use '--skip-lock-file' flag to skip deleting the '.terraform.lock.hcl' file.\n\n" + - "If no component or stack is specified, the clean operation will apply globally to all components.\n\n" + - "For more details refer to https://atmos.tools/cli/commands/terraform/clean\n") - - } else if componentType == "terraform" && command == "deploy" { - u.PrintMessage("\n'atmos terraform deploy' command executes 'terraform apply -auto-approve' on an Atmos component in an Atmos stack.\n\n" + - "Usage: atmos terraform deploy -s \n\n" + - "The command automatically sets '-auto-approve' flag when running 'terraform apply'.\n\n" + - "It supports '--deploy-run-init=true|false' flag to enable/disable running terraform init before executing the command.\n\n" + - "It supports '--from-plan' flag. If the flag is specified, the command will use the planfile previously generated by 'atmos terraform plan' " + - "command instead of generating a new planfile.\nNote that in this case, the planfile name is in the format supported by Atmos and is " + - "saved to the component's folder.\n\n" + - "It supports '--planfile' flag to specify the path to a planfile.\nThe '--planfile' flag should be used instead of the 'planfile' " + - "argument in the native 'terraform apply ' command.\n\n" + - "For more details refer to https://atmos.tools/cli/commands/terraform/deploy\n") - } else if componentType == "terraform" && command == "shell" { - u.PrintMessage("\n'atmos terraform shell' command starts a new SHELL configured with the environment for an Atmos component " + - "in a Stack to allow executing all native terraform commands\ninside the shell without using the atmos-specific arguments and flags.\n\n" + - "Usage: atmos terraform shell -s \n\n" + - "The command does the following:\n\n" + - " - Processes the stack config files, generates the required variables for the Atmos component in the stack, and writes them to a file in the component's folder\n" + - " - Generates a backend config file for the Atmos component in the stack and writes it to a file in the component's folder (or as specified by the Atmos configuration setting)\n" + - " - Creates a Terraform workspace for the component in the stack\n" + - " - Drops the user into a separate shell (process) with all the required paths and ENV vars set\n" + - " - Inside the shell, the user can execute all Terraform commands using the native syntax\n\n" + - "For more details refer to https://atmos.tools/cli/commands/terraform/shell\n") - } else if componentType == "terraform" && command == "workspace" { - u.PrintMessage("\n'atmos terraform workspace' command calculates the Terraform workspace for an Atmos component,\n" + - "and then executes 'terraform init -reconfigure' and selects the Terraform workspace by executing the 'terraform workspace select' command.\n" + - "If the workspace does not exist, the command creates it by executing the 'terraform workspace new' command.\n\n" + - "Usage: atmos terraform workspace -s \n\n" + - "For more details refer to https://atmos.tools/cli/commands/terraform/workspace\n") } else { u.PrintMessage(fmt.Sprintf("\nAtmos supports native '%s' commands with all the options, arguments and flags.\n", componentType)) u.PrintMessage("In addition, 'component' and 'stack' are required in order to generate variables for the component in the stack.\n")