-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.go
More file actions
91 lines (74 loc) · 2.53 KB
/
remove.go
File metadata and controls
91 lines (74 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/techishthoughts/gitshift/internal/config"
)
// removeCmd represents the remove command
var removeCmd = &cobra.Command{
Use: "remove [alias]",
Short: "Remove a Git platform account",
Long: `Remove a Git platform account from the configuration.
This will permanently delete the account configuration. If the account
being removed is currently active, the system will automatically switch
to another account if available.
Works with accounts from all platforms:
- GitHub (github.com and GitHub Enterprise)
- GitLab (gitlab.com and self-hosted)
- Bitbucket (coming soon)
- Custom Git platforms
Examples:
# Remove GitHub account
gitshift remove work-github
gitshift remove personal-github
# Remove GitLab account
gitshift remove work-gitlab
gitshift remove personal-gitlab`,
Aliases: []string{"rm", "delete", "del"},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
alias := args[0]
configManager := config.NewManager()
if err := configManager.Load(); err != nil {
return fmt.Errorf("failed to load configuration: %w", err)
}
// Check if the account exists
account, err := configManager.GetAccount(alias)
if err != nil {
return fmt.Errorf("account '%s' not found", alias)
}
// Ask for confirmation unless --force flag is used
force, _ := cmd.Flags().GetBool("force")
if !force {
fmt.Printf("Are you sure you want to remove account '%s'? (%s - %s) [y/N]: ",
account.Alias, account.Name, account.Email)
confirmation := promptForInput("")
if confirmation != "y" && confirmation != "Y" && confirmation != "yes" && confirmation != "Yes" {
fmt.Println("Operation cancelled.")
return nil
}
}
// Remove the account
if err := configManager.RemoveAccount(alias); err != nil {
return fmt.Errorf("failed to remove account: %w", err)
}
fmt.Printf("✅ Successfully removed account '%s'\n", alias)
// Check if there are any accounts left
accounts := configManager.ListAccounts()
if len(accounts) == 0 {
fmt.Println("No accounts remaining. Use 'gitshift add' to add a new account.")
} else {
currentAccount := configManager.GetConfig().CurrentAccount
if currentAccount != "" {
fmt.Printf("Current active account: %s\n", currentAccount)
} else {
fmt.Println("No active account set. Use 'gitshift switch' to select one.")
}
}
return nil
},
}
func init() {
rootCmd.AddCommand(removeCmd)
removeCmd.Flags().BoolP("force", "f", false, "Force removal without confirmation")
}