This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 327
Modify project destroy
to require -p
flag and delete projects created in UI without data source
#4212
Merged
Merged
Modify project destroy
to require -p
flag and delete projects created in UI without data source
#4212
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a211495
update project destroy
xiaolin-ninja 01002ce
fix return if no project
xiaolin-ninja 0a657f0
enforce -project flag
xiaolin-ninja 94422c0
just delete if no remote source
xiaolin-ninja 3acb37c
typo
xiaolin-ninja 761e4ab
fix import order
xiaolin-ninja e899dc7
changelog
xiaolin-ninja d72083d
update notes
xiaolin-ninja df106dc
update error
xiaolin-ninja dc21b51
update help string
xiaolin-ninja 5f61682
update comment
xiaolin-ninja d6f00c5
update docs
xiaolin-ninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 @@ | ||
```release-note:improvement | ||
cli: `project destroy` requires the `-project` or `-p` flag regardless of where it's run. | ||
``` | ||
|
||
```release-note:bug | ||
cli: `project destroy` now successfully destroys a project created in the UI without a remote source or local hcl file. | ||
``` |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package cli | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/hashicorp/waypoint-plugin-sdk/terminal" | ||
"github.com/hashicorp/waypoint/internal/clierrors" | ||
"github.com/hashicorp/waypoint/internal/pkg/flag" | ||
pb "github.com/hashicorp/waypoint/pkg/server/gen" | ||
"strings" | ||
) | ||
|
||
type ProjectDestroyCommand struct { | ||
|
@@ -24,20 +25,21 @@ func (c *ProjectDestroyCommand) Run(args []string) int { | |
return 1 | ||
} | ||
|
||
if c.project == nil { | ||
c.ui.Output("The -project flag must be set.", terminal.WithErrorStyle()) | ||
if c.flagProject == "" { | ||
c.ui.Output("Must explicitly set -project (-p) flag to destroy project.", terminal.WithErrorStyle()) | ||
return 1 | ||
} | ||
|
||
// Get the project we're destroying | ||
// Verify the project we're destroying exists | ||
project, err := c.project.Client().GetProject(c.Ctx, &pb.GetProjectRequest{ | ||
Project: c.project.Ref(), | ||
}) | ||
if err != nil { | ||
c.ui.Output("Project %q not found.", c.project.Ref().Project, terminal.WithErrorStyle()) | ||
return 1 | ||
} | ||
|
||
// Confirmation is required for destroying a project &/or its resources | ||
// Confirmation required without `-auto-approve` flag | ||
if !c.confirm { | ||
proceed, err := c.ui.Input(&terminal.Input{ | ||
Prompt: "Do you really want to destroy project \"" + project.Project.Name + "\" and its resources? Only 'yes' will be accepted to approve: ", | ||
|
@@ -56,12 +58,19 @@ func (c *ProjectDestroyCommand) Run(args []string) int { | |
return 1 | ||
} | ||
} | ||
_, err = c.project.DestroyProject(c.Ctx, &pb.Job_DestroyProjectOp{ | ||
Project: &pb.Ref_Project{Project: project.Project.Name}, | ||
SkipDestroyResources: c.skipDestroyResources, | ||
}) | ||
|
||
if project.Project.DataSource == nil { | ||
_, err = c.project.Client().DestroyProject(c.Ctx, &pb.DestroyProjectRequest{ | ||
Project: c.project.Ref(), | ||
}) | ||
} else { | ||
_, err = c.project.DestroyProject(c.Ctx, &pb.Job_DestroyProjectOp{ | ||
Project: &pb.Ref_Project{Project: project.Project.Name}, | ||
SkipDestroyResources: c.skipDestroyResources, | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This confused me at first - I wasn't sure what the difference was between these two |
||
} | ||
if err != nil { | ||
c.ui.Output("Error destroying project: %s", err.Error(), terminal.WithErrorStyle()) | ||
c.ui.Output("Error destroying project %q: %s", project.Project.Name, err.Error(), terminal.WithErrorStyle()) | ||
return 1 | ||
} | ||
c.ui.Output("Project %q destroyed!", project.Project.Name, terminal.WithSuccessStyle()) | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd reprint the help text here with
c.Flags().Help()
.Something like that.
Then we should update the usage string to explicitly show that the flag is now required: