Skip to content

Commit 2d325b9

Browse files
authored
add mass package reset command (#203)
* add mass package reset command * review changes
1 parent d0e59d9 commit 2d325b9

23 files changed

+586
-118
lines changed

cmd/package.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/massdriver-cloud/mass/pkg/api"
1616
"github.com/massdriver-cloud/mass/pkg/commands/pkg"
1717
"github.com/massdriver-cloud/mass/pkg/files"
18+
"github.com/massdriver-cloud/mass/pkg/prettylogs"
1819

1920
"github.com/charmbracelet/glamour"
2021
"github.com/charmbracelet/lipgloss"
@@ -122,6 +123,16 @@ func NewCmdPkg() *cobra.Command {
122123
}
123124
pkgDestroyCmd.Flags().BoolP("force", "f", false, "Skip confirmation prompt")
124125

126+
pkgResetCmd := &cobra.Command{
127+
Use: `reset <project>-<env>-<manifest>`,
128+
Short: "Reset package status to 'Initialized'",
129+
Example: `mass package reset api-prod-db`,
130+
Long: helpdocs.MustRender("package/reset"),
131+
Args: cobra.ExactArgs(1),
132+
RunE: runPkgReset,
133+
}
134+
pkgResetCmd.Flags().BoolP("force", "f", false, "Skip confirmation prompt")
135+
125136
pkgCmd.AddCommand(pkgConfigureCmd)
126137
pkgCmd.AddCommand(pkgDeployCmd)
127138
pkgCmd.AddCommand(pkgExportCmd)
@@ -130,6 +141,7 @@ func NewCmdPkg() *cobra.Command {
130141
pkgCmd.AddCommand(pkgCreateCmd)
131142
pkgCmd.AddCommand(pkgVersionCmd)
132143
pkgCmd.AddCommand(pkgDestroyCmd)
144+
pkgCmd.AddCommand(pkgResetCmd)
133145

134146
return pkgCmd
135147
}
@@ -456,3 +468,52 @@ func runPkgDestroy(cmd *cobra.Command, args []string) error {
456468

457469
return nil
458470
}
471+
472+
func runPkgReset(cmd *cobra.Command, args []string) error {
473+
ctx := context.Background()
474+
475+
packageSlugOrID := args[0]
476+
477+
force, err := cmd.Flags().GetBool("force")
478+
if err != nil {
479+
return err
480+
}
481+
482+
cmd.SilenceUsage = true
483+
484+
mdClient, mdClientErr := client.New()
485+
if mdClientErr != nil {
486+
return fmt.Errorf("error initializing massdriver client: %w", mdClientErr)
487+
}
488+
489+
// Get package details for confirmation
490+
pkgDetails, err := api.GetPackage(ctx, mdClient, packageSlugOrID)
491+
if err != nil {
492+
return err
493+
}
494+
495+
// Prompt for confirmation unless --force is used
496+
if !force {
497+
fmt.Printf("%s: This will reset package `%s` to 'Initialized' state and delete deployment history.\n", prettylogs.Orange("WARNING"), pkgDetails.Slug)
498+
fmt.Printf("Type `%s` to confirm reset: ", pkgDetails.Slug)
499+
reader := bufio.NewReader(os.Stdin)
500+
answer, _ := reader.ReadString('\n')
501+
answer = strings.TrimSpace(answer)
502+
503+
if answer != pkgDetails.Slug {
504+
fmt.Println("Reset cancelled.")
505+
return nil
506+
}
507+
}
508+
509+
pkg, err := pkg.RunReset(ctx, mdClient, packageSlugOrID)
510+
if err != nil {
511+
return err
512+
}
513+
514+
var name = lipgloss.NewStyle().SetString(pkg.Slug).Foreground(lipgloss.Color("#7D56F4"))
515+
msg := fmt.Sprintf("✅ Package %s reset successfully", name)
516+
fmt.Println(msg)
517+
518+
return nil
519+
}

docs/generated/mass_artifact.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ Manage artifacts
1414

1515
Artifacts represent infrastructure resources and connections in Massdriver. They can be provisioned by bundles or manually imported.
1616

17-
## Commands
18-
19-
- `get`: Retrieve an artifact's details and metadata
20-
- `download`: Download an artifact in the specified format
21-
- `import`: Import a custom artifact
22-
2317

2418
### Options
2519

docs/generated/mass_credential.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ Credential management
1414

1515
Manage credential artifacts in your organization.
1616

17-
## Commands
18-
19-
- `list`: List all credential artifacts
20-
2117

2218
### Options
2319

docs/generated/mass_definition.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ Artifact definitions are used to:
2020
- Control how artifacts are displayed in the UI
2121
- Define connections between artifacts
2222

23-
## Commands
24-
25-
- `get`: Retrieve an artifact definition's schema and metadata
26-
- `list`: List all available artifact definitions
27-
- `publish`: Publish a new or updated artifact definition
28-
- `delete`: Delete an artifact definition (requires administrator permissions)
29-
3023

3124
### Options
3225

docs/generated/mass_environment.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ Environment management
1616

1717
Environments can be modeled by application stage (production, staging, development), by region (prod-usw, prod-eu), and even ephemerally per developer (alice-dev, bob-dev).
1818

19-
## Commands
20-
21-
- `export`: Export an environment to local filesystem
22-
- `get`: Retrieve environment details and configuration
23-
- `list`: List all environments in a project
24-
- `default`: Set an artifact as the default connection for an environment
25-
2619

2720
### Options
2821

docs/generated/mass_logs.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
id: mass_logs.md
3+
slug: /cli/commands/mass_logs
4+
title: Mass Logs
5+
sidebar_label: Mass Logs
6+
---
7+
## mass logs
8+
9+
Get deployment logs
10+
11+
### Synopsis
12+
13+
# Get Deployment Logs
14+
15+
Retrieves and outputs the log stream for a specific deployment. The logs are dumped to stdout in their original format.
16+
17+
## Usage
18+
19+
```bash
20+
mass logs <deployment-id>
21+
```
22+
23+
Where `<deployment-id>` is the UUID of the deployment.
24+
25+
## Examples
26+
27+
```bash
28+
# Get logs for a deployment
29+
mass logs 12345678-1234-1234-1234-123456789012
30+
31+
# Pipe logs to a file
32+
mass logs 12345678-1234-1234-1234-123456789012 > deployment.log
33+
```
34+
35+
## Notes
36+
37+
- Logs are output to stdout in their original format
38+
- This command does not support tailing/following logs - it dumps all available logs
39+
- The deployment ID can be found in the Massdriver UI or from deployment-related commands
40+
41+
42+
```
43+
mass logs [deployment-id] [flags]
44+
```
45+
46+
### Examples
47+
48+
```
49+
# Get logs for a deployment
50+
mass logs 12345678-1234-1234-1234-123456789012
51+
```
52+
53+
### Options
54+
55+
```
56+
-h, --help help for logs
57+
```
58+
59+
### SEE ALSO
60+
61+
* [mass](/cli/commands/mass) - Massdriver Cloud CLI

docs/generated/mass_package.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ Packages are used to:
2020
- Manage environment-specific settings
2121
- Connect different components together
2222

23-
## Commands
24-
25-
- `configure`: Update package configuration
26-
- `deploy`: Deploy a package to an environment
27-
- `export`: Export a package to your local filesystem
28-
- `get`: Retrieve package details and configuration
29-
- `patch`: Update individual package parameter values
30-
3123

3224
### Options
3325

@@ -45,4 +37,5 @@ Packages are used to:
4537
* [mass package export](/cli/commands/mass_package_export) - Export packages
4638
* [mass package get](/cli/commands/mass_package_get) - Get a package
4739
* [mass package patch](/cli/commands/mass_package_patch) - Patch individual package parameter values
40+
* [mass package reset](/cli/commands/mass_package_reset) - Reset package status to 'Initialized'
4841
* [mass package version](/cli/commands/mass_package_version) - Set package version
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
id: mass_package_reset.md
3+
slug: /cli/commands/mass_package_reset
4+
title: Mass Package Reset
5+
sidebar_label: Mass Package Reset
6+
---
7+
## mass package reset
8+
9+
Reset package status to 'Initialized'
10+
11+
### Synopsis
12+
13+
# Reset Package Status
14+
15+
This command allows you to reset a package status back to 'Initialized'. This should only be used when a package is in an unrecoverable state - common situations include a package stuck in 'Pending' due to deployment issues, or a package that cannot be successfully decommissioned due to deployment failures.
16+
17+
## Examples
18+
19+
You can reset the package using the `slug` identifier.
20+
21+
The `slug` can be found by hovering over the bundle in the Massdriver diagram. The package slug is a combination of the `<project-slug>-<env-slug>-<manifest-slug>`
22+
23+
Reset and delete the deployment history:
24+
25+
```shell
26+
mass package reset ecomm-prod-vpc
27+
```
28+
29+
30+
```
31+
mass package reset <project>-<env>-<manifest> [flags]
32+
```
33+
34+
### Examples
35+
36+
```
37+
mass package reset api-prod-db
38+
```
39+
40+
### Options
41+
42+
```
43+
-f, --force Skip confirmation prompt
44+
-h, --help help for reset
45+
```
46+
47+
### SEE ALSO
48+
49+
* [mass package](/cli/commands/mass_package) - Manage packages of IaC deployed in environments.

docs/generated/mass_project.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ Project management
1616

1717
A project can encompass many environments (permanent or ephemeral) and manages the parity across those environments.
1818

19-
## Commands
20-
21-
- `export`: Export a project to your local filesystem
22-
- `get`: Retrieve project details and configuration
23-
- `list`: List all projects in your organization
24-
2519

2620
### Options
2721

docs/helpdocs/artifact.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
# Manage Massdriver artifacts
22

33
Artifacts represent infrastructure resources and connections in Massdriver. They can be provisioned by bundles or manually imported.
4-
5-
## Commands
6-
7-
- `get`: Retrieve an artifact's details and metadata
8-
- `download`: Download an artifact in the specified format
9-
- `import`: Import a custom artifact

0 commit comments

Comments
 (0)