Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: start work autoapply command for enabling/disabling gated deploy…
… requests
- Loading branch information
1 parent
9747876
commit 0672633
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package deployrequest | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/planetscale/cli/internal/cmdutil" | ||
"github.com/planetscale/cli/internal/printer" | ||
"github.com/planetscale/planetscale-go/planetscale" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// AutoApplyCmd is the command for enabling/disabling auto applying a gated deploy requests. | ||
func AutoApplyCmd(ch *cmdutil.Helper) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "auto-apply <database> <number> <option>", | ||
Short: "Auto apply changes to a gated deploy request", | ||
Args: cmdutil.RequiredArgs("database", "number", "option"), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
database := args[0] | ||
number := args[1] | ||
|
||
client, err := ch.Client() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
n, err := strconv.ParseUint(number, 10, 64) | ||
if err != nil { | ||
return fmt.Errorf("the argument <number> is invalid: %s", err) | ||
} | ||
|
||
dr, err := client.DeployRequests.CancelDeploy(ctx, &planetscale.CancelDeployRequestRequest{ | ||
Organization: ch.Config.Organization, | ||
Database: database, | ||
Number: n, | ||
}) | ||
if err != nil { | ||
switch cmdutil.ErrCode(err) { | ||
case planetscale.ErrNotFound: | ||
return fmt.Errorf("deploy request '%s/%s' does not exist in organization %s", | ||
printer.BoldBlue(database), printer.BoldBlue(number), printer.BoldBlue(ch.Config.Organization)) | ||
default: | ||
return cmdutil.HandleError(err) | ||
} | ||
} | ||
|
||
if ch.Printer.Format() == printer.Human { | ||
ch.Printer.Printf("Successfully enabled auto-apply changes for '%s/%s'.\n", | ||
printer.BoldBlue(database), | ||
printer.BoldBlue(dr.Number)) | ||
return nil | ||
} | ||
|
||
return ch.Printer.PrintResource(toDeployRequest(dr)) | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters