Skip to content

Commit b827c40

Browse files
authored
Merge pull request #283 from spacelift-io/feat-added-sync-commit-stack-subcommand
feat: added stack sync-commit subcommand
2 parents 63593f3 + 7b9218e commit b827c40

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

internal/cmd/stack/stack.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,17 @@ func Command() *cli.Command {
405405
Before: authenticated.Ensure,
406406
ArgsUsage: cmd.EmptyArgsUsage,
407407
},
408+
{
409+
Category: "Stack management",
410+
Name: "sync-commit",
411+
Usage: "Syncs the tracked stack commit",
412+
Flags: []cli.Flag{
413+
flagStackID,
414+
},
415+
Action: syncCommit,
416+
Before: authenticated.Ensure,
417+
ArgsUsage: cmd.EmptyArgsUsage,
418+
},
408419
{
409420
Name: "resources",
410421
Usage: "Manage and view resources for stacks",

internal/cmd/stack/sync.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package stack
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/shurcooL/graphql"
7+
"github.com/spacelift-io/spacectl/internal/cmd/authenticated"
8+
"github.com/urfave/cli/v2"
9+
)
10+
11+
func syncCommit(cliCtx *cli.Context) error {
12+
stackID, err := getStackID(cliCtx)
13+
if err != nil {
14+
return err
15+
}
16+
17+
if nArgs := cliCtx.NArg(); nArgs != 0 {
18+
return fmt.Errorf("expected zero arguments but got %d", nArgs)
19+
}
20+
21+
var mutation struct {
22+
Stack struct {
23+
ID string `graphql:"id"`
24+
} `graphql:"stackSyncCommit(id: $stack)"`
25+
}
26+
variables := map[string]interface{}{
27+
"stack": graphql.ID(stackID),
28+
}
29+
30+
return authenticated.Client.Mutate(cliCtx.Context, &mutation, variables)
31+
}

0 commit comments

Comments
 (0)