diff --git a/internal/cmd/module/delete_version.go b/internal/cmd/module/delete_version.go new file mode 100644 index 0000000..07fade2 --- /dev/null +++ b/internal/cmd/module/delete_version.go @@ -0,0 +1,32 @@ +package module + +import ( + "fmt" + + "github.com/shurcooL/graphql" + "github.com/spacelift-io/spacectl/internal/cmd/authenticated" + "github.com/urfave/cli/v2" +) + +func deleteVersion(cliCtx *cli.Context) error { + moduleID := cliCtx.String(flagModuleID.Name) + versionID := cliCtx.String(flagVersionID.Name) + + var mutation struct { + DeleteModuleVersion struct { + Number string `graphql:"number"` + } `graphql:"versionDelete(id: $id, module: $module)"` + } + + variables := map[string]interface{}{ + "id": graphql.ID(versionID), + "module": graphql.ID(moduleID), + } + + if err := authenticated.Client.Mutate(cliCtx.Context, &mutation, variables); err != nil { + return err + } + + fmt.Printf("Module version %q has been deleted\n", mutation.DeleteModuleVersion.Number) + return nil +} diff --git a/internal/cmd/module/flags.go b/internal/cmd/module/flags.go index 5e554b1..6b4254f 100644 --- a/internal/cmd/module/flags.go +++ b/internal/cmd/module/flags.go @@ -8,6 +8,12 @@ var flagModuleID = &cli.StringFlag{ Required: true, } +var flagVersionID = &cli.StringFlag{ + Name: "versionid", + Usage: "[Required] User-facing `ID` (slug) of the version", + Required: true, +} + var flagCommitSHA = &cli.StringFlag{ Name: "sha", Usage: "Commit `SHA` to use for the module version", diff --git a/internal/cmd/module/module.go b/internal/cmd/module/module.go index bf6c8ab..f489777 100644 --- a/internal/cmd/module/module.go +++ b/internal/cmd/module/module.go @@ -25,6 +25,18 @@ func Command() *cli.Command { Before: authenticated.Ensure, ArgsUsage: cmd.EmptyArgsUsage, }, + { + Category: "Module management", + Name: "delete-version", + Usage: "Delete a version of a module", + Flags: []cli.Flag{ + flagModuleID, + flagVersionID, + }, + Action: deleteVersion, + Before: authenticated.Ensure, + ArgsUsage: cmd.EmptyArgsUsage, + }, { Category: "Module management", Name: "local-preview",