Skip to content

Commit

Permalink
stack: add enable + disable commands
Browse files Browse the repository at this point in the history
  • Loading branch information
lexton committed Dec 20, 2022
1 parent 4ba3ee8 commit c575e83
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
47 changes: 47 additions & 0 deletions internal/cmd/stack/enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package stack

import (
"fmt"

"github.com/shurcooL/graphql"
"github.com/spacelift-io/spacectl/internal/cmd/authenticated"
"github.com/urfave/cli/v2"
)

type (
stackEnableMutation struct {
Stack struct {
ID string `graphql:"id"`
Disabled bool `graphql:"isDisabled"`
} `graphql:"stackEnable(id: $stack)"`
}
stackDisableMutation struct {
Stack struct {
ID string `graphql:"id"`
Disabled bool `graphql:"isDisabled"`
} `graphql:"stackDisable(id: $stack)"`
}
)

func enable(cliCtx *cli.Context) error {
return enableDisable[stackEnableMutation](cliCtx)
}

func disable(cliCtx *cli.Context) error {
return enableDisable[stackDisableMutation](cliCtx)
}

func enableDisable[T any](cliCtx *cli.Context) error {
stackID := cliCtx.String(flagStackID.Name)

if nArgs := cliCtx.NArg(); nArgs != 0 {
return fmt.Errorf("expected zero arguments but got %d", nArgs)
}

var mutation T
variables := map[string]interface{}{
"stack": graphql.ID(stackID),
}

return authenticated.Client.Mutate(cliCtx.Context, &mutation, variables)
}
22 changes: 22 additions & 0 deletions internal/cmd/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,28 @@ func Command() *cli.Command {
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
{
Category: "Stack management",
Name: "enable",
Usage: "Enable new runs against the stack",
Flags: []cli.Flag{
flagStackID,
},
Action: enable,
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
{
Category: "Stack management",
Name: "disable",
Usage: "Disable new runs against the stack",
Flags: []cli.Flag{
flagStackID,
},
Action: disable,
Before: authenticated.Ensure,
ArgsUsage: cmd.EmptyArgsUsage,
},
},
}
}

0 comments on commit c575e83

Please sign in to comment.