Skip to content

Commit

Permalink
refactor: ♻️ rename delete command to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChung committed Apr 9, 2023
1 parent 6d77536 commit e8ebe57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cmd/codecommit/branch/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/kubectl/pkg/util/templates"

"github.com/JamesChung/cprl/cmd/codecommit/branch/del"
"github.com/JamesChung/cprl/cmd/codecommit/branch/remove"
"github.com/JamesChung/cprl/pkg/util"
)

Expand All @@ -23,7 +23,7 @@ func setPersistentFlags(flags *pflag.FlagSet) {

func branchCommands() []*cobra.Command {
return []*cobra.Command{
del.NewCmd(),
remove.NewCmd(),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package del
package remove

import (
"fmt"
Expand All @@ -15,13 +15,13 @@ import (
)

var (
shortMessage = "Delete branches"
shortMessage = "Remove branches"

longMessage = templates.LongDesc(`
Delete a branch`)
Removes branches`)

example = templates.Examples(`
cprl codecommit branch delete
cprl codecommit branch remove
`)
)

Expand All @@ -35,8 +35,8 @@ func setPersistentFlags(flags *pflag.FlagSet) {

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Aliases: []string{"d", "del"},
Use: "remove",
Aliases: []string{"r", "rem"},
Short: shortMessage,
Long: longMessage,
Example: example,
Expand Down Expand Up @@ -73,28 +73,28 @@ func runCmd(cmd *cobra.Command, args []string) {
})
util.ExitOnErr(err)

// Prompt for branches to delete
// Prompt for branches to remove
branchSelections, err := pterm.DefaultInteractiveMultiselect.
WithOptions(branches).Show("Select branches to delete")
WithOptions(branches).Show("Select branches to remove")
util.ExitOnErr(err)

// Delete branches
// Remove branches
var results []util.Result[string]
util.Spinner("Deleting...", func() {
util.Spinner("Removing...", func() {
results = util.DeleteBranches(ccClient, repo, branchSelections)
})

failCount := 0
for _, r := range results {
if r.Err != nil {
pterm.Error.Printf("Failed to delete branch [%s]\n", r.Result)
pterm.Error.Printf("Failed to remove branch [%s]\n", r.Result)
failCount++
continue
}
pterm.Success.Printf("Successfully deleted branch [%s]\n", r.Result)
pterm.Success.Printf("Successfully removed branch [%s]\n", r.Result)
}

if failCount > 0 {
util.ExitOnErr(fmt.Errorf("Failed to delete %d branches\n", failCount))
util.ExitOnErr(fmt.Errorf("Failed to remove %d branches\n", failCount))
}
}

0 comments on commit e8ebe57

Please sign in to comment.