-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stack: add enable + disable commands
- Loading branch information
Showing
2 changed files
with
69 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,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) | ||
} |
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