Skip to content

Commit

Permalink
Allow to delete a module version (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasmik authored Sep 13, 2024
1 parent 0f00fed commit dd17a6f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
32 changes: 32 additions & 0 deletions internal/cmd/module/delete_version.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions internal/cmd/module/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions internal/cmd/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dd17a6f

Please sign in to comment.