-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
``` ➜ spacectl git:(main) ✗ spc stack cancel --id testing-component --run 01HCHMRJ9JF64E41B4NR5FQ87Q You have successfully canceled a run The run can be visited at http://tomasmik.app.spacelift.tf/stack/testing-component/run/01HCHMRJ9JF64E41B4NR5FQ87Q ➜ spacectl git:(main) ✗ spc stack cancel --id testing-component --run 01HCHMZWE9CAVKGWHN2E2CZ7K3 --tail You have successfully canceled a run The run can be visited at http://tomasmik.app.spacelift.tf/stack/testing-component/run/01HCHMZWE9CAVKGWHN2E2CZ7K3 ----------------- QUEUED Thu Oct 12 12:55:23 EEST 2023 ----------------- ----------------- CANCELED Fri Oct 13 12:49:40 EEST 2023 api::01HBR32BK0ZD84TB1DKF83D760 ----------------- 2023/10/13 12:49:40 finished with CANCELED state ```
- 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,56 @@ | ||
package stack | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/shurcooL/graphql" | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/spacelift-io/spacectl/internal/cmd/authenticated" | ||
) | ||
|
||
func runCancel() cli.ActionFunc { | ||
return func(cliCtx *cli.Context) error { | ||
stackID, err := getStackID(cliCtx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var mutation struct { | ||
RunDiscard struct { | ||
ID string `graphql:"id"` | ||
} `graphql:"runCancel(stack: $stack, run: $run)"` | ||
} | ||
|
||
variables := map[string]interface{}{ | ||
"stack": graphql.ID(stackID), | ||
"run": graphql.ID(cliCtx.String(flagRequiredRun.Name)), | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
if err := authenticated.Client.Mutate(ctx, &mutation, variables); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println("You have successfully canceled a run") | ||
|
||
fmt.Println("The run can be visited at", authenticated.Client.URL( | ||
"/stack/%s/run/%s", | ||
stackID, | ||
mutation.RunDiscard.ID, | ||
)) | ||
|
||
if !cliCtx.Bool(flagTail.Name) { | ||
return nil | ||
} | ||
|
||
terminal, err := runLogsWithAction(ctx, stackID, mutation.RunDiscard.ID, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return terminal.Error() | ||
} | ||
} |
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