From 4ae1625b0d7bfcd09ab53c2375b6f5de96d65e37 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Fri, 22 Dec 2023 16:33:22 -0500 Subject: [PATCH] internal/cmd/branch: clean up demote Signed-off-by: Matt Layher --- internal/cmd/branch/demote.go | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/internal/cmd/branch/demote.go b/internal/cmd/branch/demote.go index a7c9d733..6fc65d93 100644 --- a/internal/cmd/branch/demote.go +++ b/internal/cmd/branch/demote.go @@ -11,36 +11,32 @@ import ( ) func DemoteCmd(ch *cmdutil.Helper) *cobra.Command { - demoteReq := &ps.DemoteRequest{} - - cmd := &cobra.Command{ + return &cobra.Command{ Use: "demote [options]", Short: "Demote a production branch to development", Args: cmdutil.RequiredArgs("database", "branch"), RunE: func(cmd *cobra.Command, args []string) error { - ctx := cmd.Context() - - database := args[0] - branch := args[1] - - demoteReq.Database = database - demoteReq.Branch = branch - demoteReq.Organization = ch.Config.Organization + req := &ps.DemoteRequest{ + Database: args[0], + Branch: args[1], + Organization: ch.Config.Organization, + } client, err := ch.Client() if err != nil { return err } - end := ch.Printer.PrintProgress(fmt.Sprintf("Demoting %s branch in %s to development...", printer.BoldBlue(branch), printer.BoldBlue(database))) + end := ch.Printer.PrintProgress(fmt.Sprintf("Demoting %s branch in %s to development...", + printer.BoldBlue(req.Branch), printer.BoldBlue(req.Database))) defer end() - b, err := client.DatabaseBranches.Demote(ctx, demoteReq) + b, err := client.DatabaseBranches.Demote(cmd.Context(), req) if err != nil { switch cmdutil.ErrCode(err) { case ps.ErrNotFound: return fmt.Errorf("branch %s does not exist in database %s", - printer.BoldBlue(branch), printer.BoldBlue(database)) + printer.BoldBlue(req.Branch), printer.BoldBlue(req.Database)) default: return cmdutil.HandleError(err) } @@ -49,16 +45,11 @@ func DemoteCmd(ch *cmdutil.Helper) *cobra.Command { end() if ch.Printer.Format() == printer.Human { - ch.Printer.Printf("%s branch was successfully demoted to development.\n", printer.BoldBlue(branch)) + ch.Printer.Printf("%s branch was successfully demoted to development.\n", printer.BoldBlue(req.Branch)) return nil - } else { - if err != nil { - return cmdutil.HandleError(err) - } - return ch.Printer.PrintResource(ToDatabaseBranch(b)) } + + return ch.Printer.PrintResource(ToDatabaseBranch(b)) }, } - - return cmd }