-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: project delete #112
Merged
Merged
feat: project delete #112
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c929a32
refactored common confirmation flag
benPearce1 ef0ce8b
added project delete
benPearce1 d7c7450
fix project query and client creation
benPearce1 93358b9
corrected short hand value for confirm
benPearce1 2b1330e
cleanup
benPearce1 759c6da
reorder paramters
benPearce1 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
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
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
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
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,94 @@ | ||
package delete | ||
|
||
import ( | ||
"github.com/MakeNowJust/heredoc/v2" | ||
"github.com/OctopusDeploy/cli/pkg/factory" | ||
"github.com/OctopusDeploy/cli/pkg/question" | ||
"github.com/OctopusDeploy/cli/pkg/question/selectors" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type DeleteOptions struct { | ||
Client *client.Client | ||
Ask question.Asker | ||
NoPrompt bool | ||
IdOrName string | ||
*question.DeleteFlags | ||
} | ||
|
||
func NewCmdList(f factory.Factory) *cobra.Command { | ||
deleteFlags := question.NewDeleteFlags() | ||
cmd := &cobra.Command{ | ||
Use: "delete {<name> | <id> | <slug>}", | ||
Short: "Delete projects in Octopus Deploy", | ||
Long: "Delete projects in Octopus Deploy", | ||
Aliases: []string{"del", "rm", "remove"}, | ||
Example: heredoc.Doc(` | ||
$ octopus project delete | ||
$ octopus project rm | ||
`), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client, err := f.GetSpacedClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
opts := &DeleteOptions{ | ||
Client: client, | ||
Ask: f.Ask, | ||
NoPrompt: !f.IsPromptEnabled(), | ||
IdOrName: args[0], | ||
DeleteFlags: deleteFlags, | ||
} | ||
|
||
return deleteRun(opts) | ||
}, | ||
} | ||
|
||
question.RegisterDeleteFlag(cmd, &deleteFlags.Confirm.Value, "project") | ||
|
||
return cmd | ||
} | ||
|
||
func deleteRun(opts *DeleteOptions) error { | ||
if !opts.NoPrompt { | ||
if err := PromptMissing(opts); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
itemToDelete, err := opts.Client.Projects.GetByIdOrName(opts.IdOrName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if opts.DeleteFlags.Confirm.Value { | ||
return delete(opts.Client, itemToDelete) | ||
} else { | ||
return question.DeleteWithConfirmation(opts.Ask, "project", itemToDelete.Name, itemToDelete.ID, func() error { | ||
return delete(opts.Client, itemToDelete) | ||
}) | ||
} | ||
} | ||
|
||
func PromptMissing(opts *DeleteOptions) error { | ||
if opts.IdOrName == "" { | ||
existingProjects, err := opts.Client.Projects.GetAll() | ||
if err != nil { | ||
return err | ||
} | ||
itemToDelete, err := selectors.ByNameOrID(opts.Ask, existingProjects, "Select the project you wish to delete:") | ||
if err != nil { | ||
return err | ||
} | ||
opts.IdOrName = itemToDelete.GetID() | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func delete(client *client.Client, project *projects.Project) error { | ||
return client.Projects.DeleteByID(project.GetID()) | ||
} |
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
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
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.
Let's update this to use the new dependencies struct we made for project create, maybe in a future PR?
For now let's remove the opts that are not being used.
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 have removed the unused ones, can fix things up after
project create
goes in