diff --git a/cmd/ocm/delete/cmd.go b/cmd/ocm/delete/cmd.go index b4391ff0..83311af9 100644 --- a/cmd/ocm/delete/cmd.go +++ b/cmd/ocm/delete/cmd.go @@ -40,14 +40,67 @@ var args struct { } var Cmd = &cobra.Command{ - Use: "delete [flags] PATH", + Use: "delete [flags] (PATH | RESOURCE_ALIAS RESOURCE_ID)", Short: "Send a DELETE request", Long: "Send a DELETE request to the given path.", RunE: run, ValidArgs: urls.Resources(), } +var usageTemplate = `Usage:{{if .Runnable}} +{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} +{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}} + +Aliases: +{{.NameAndAliases}}{{end}}{{if .HasExample}} + +Resource Alias: +{{.Example}}{{end}}{{if .HasAvailableSubCommands}}{{$cmds := .Commands}}{{if eq (len .Groups) 0}} + +Available Commands:{{range $cmds}}{{if (or .IsAvailableCommand (eq .Name "help"))}} +{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{else}}{{range $group := .Groups}} + +{{.Title}}{{range $cmds}}{{if (and (eq .GroupID $group.ID) (or .IsAvailableCommand (eq .Name "help")))}} +{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if not .AllChildCommandsHaveGroup}} + +Additional Commands:{{range $cmds}}{{if (and (eq .GroupID "") (or .IsAvailableCommand (eq .Name "help")))}} +{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} + +Flags: +{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} + +Global Flags: +{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}} + +Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} +{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}} + +Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}} +` + +var helpTemplate = `{{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}} + +{{end}}{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}` + +var argumentsExamples = []string{ + ` account + addon + cluster + role_binding + sku_rule + subscription`, +} + func init() { + Cmd.SetUsageTemplate(usageTemplate) + Cmd.SetHelpTemplate(helpTemplate) + for _, ex := range argumentsExamples { + if Cmd.Example == "" { + Cmd.Example = ex + } else { + Cmd.Example = fmt.Sprintf("%s\n%s", Cmd.Example, ex) + } + } fs := Cmd.Flags() arguments.AddParameterFlag(fs, &args.parameter) arguments.AddHeaderFlag(fs, &args.header) @@ -61,13 +114,13 @@ func init() { func run(cmd *cobra.Command, argv []string) error { path, err := urls.Expand(argv) if err != nil { - return fmt.Errorf("Could not create URI: %v", err) + return fmt.Errorf("could not create URI: %w", err) } // Create the client for the OCM API: connection, err := ocm.NewConnection().Build() if err != nil { - return fmt.Errorf("Failed to create OCM connection: %v", err) + return fmt.Errorf("failed to create OCM connection: %w", err) } defer connection.Close() @@ -84,7 +137,7 @@ func run(cmd *cobra.Command, argv []string) error { // Send the request: response, err := request.Send() if err != nil { - return fmt.Errorf("Can't send request: %v", err) + return fmt.Errorf("can't send request: %w", err) } status := response.Status() body := response.Bytes() @@ -94,26 +147,26 @@ func run(cmd *cobra.Command, argv []string) error { err = dump.Pretty(os.Stderr, body) } if err != nil { - return fmt.Errorf("Can't print body: %v", err) + return fmt.Errorf("can't print body: %w", err) } // Load the configuration file: cfg, err := config.Load() if err != nil { - return fmt.Errorf("Can't load config file: %v", err) + return fmt.Errorf("can't load config file: %w", err) } if cfg == nil { - return fmt.Errorf("Not logged in, run the 'login' command") + return fmt.Errorf("not logged in, run the 'login' command") } // Save the configuration: cfg.AccessToken, cfg.RefreshToken, err = connection.Tokens() if err != nil { - return fmt.Errorf("Can't get tokens: %v", err) + return fmt.Errorf("can't get tokens: %w", err) } err = config.Save(cfg) if err != nil { - return fmt.Errorf("Can't save config file: %v", err) + return fmt.Errorf("can't save config file: %w", err) } // Bye: