Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/harbor/root/project/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ func DeleteProjectCommand() *cobra.Command {
}
}

if !forceDelete {
msg := ""

if projectID != "" {
msg = fmt.Sprintf("Delete project ID: %s?", projectID)
} else if len(args) > 0 {
msg = fmt.Sprintf("Delete project(s): %v?", args)
} else {
msg = "Delete selected project?"
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be here either, this should be shown in the charm/huh via Title() or something

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NucleoFusion, Thanks for the feedback! Moved all prompt-related logic, including message construction, into the prompt package and updated the implementation accordingly.


confirm, err := prompt.ConfirmProjectDeletion(msg)
if err != nil {
return err
}

if !confirm {
fmt.Println("Aborted.")
return nil
}
}

if projectID != "" {
log.Debugf("Deleting project with ID: %s", projectID)
wg.Add(1)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/atotto/clipboard v0.1.4
github.com/charmbracelet/bubbles v1.0.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/huh v0.8.0
github.com/charmbracelet/huh v1.0.0
github.com/charmbracelet/lipgloss v1.1.0
github.com/sahilm/fuzzy v0.1.1
github.com/sirupsen/logrus v1.9.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
github.com/charmbracelet/huh v0.8.0 h1:Xz/Pm2h64cXQZn/Jvele4J3r7DDiqFCNIVteYukxDvY=
github.com/charmbracelet/huh v0.8.0/go.mod h1:5YVc+SlZ1IhQALxRPpkGwwEKftN/+OlJlnJYlDRFqN4=
github.com/charmbracelet/huh v1.0.0 h1:wOnedH8G4qzJbmhftTqrpppyqHakl/zbbNdXIWJyIxw=
github.com/charmbracelet/huh v1.0.0/go.mod h1:5YVc+SlZ1IhQALxRPpkGwwEKftN/+OlJlnJYlDRFqN4=
github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
Expand Down
16 changes: 16 additions & 0 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/constants"
"github.com/charmbracelet/huh"
aview "github.com/goharbor/harbor-cli/pkg/views/artifact/select"
tview "github.com/goharbor/harbor-cli/pkg/views/artifact/tags/select"
immview "github.com/goharbor/harbor-cli/pkg/views/immutable/select"
Expand Down Expand Up @@ -442,3 +443,18 @@ func GetRoleIDFromUser() int64 {

return <-roleID
}

func ConfirmProjectDeletion(message string) (bool, error) {
var confirm bool

form := huh.NewForm(
huh.NewGroup(
huh.NewConfirm().
Title(message).
Value(&confirm),
),
)

err := form.Run()
return confirm, err
}