/
remove.go
71 lines (56 loc) · 1.52 KB
/
remove.go
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
package cmd
import (
"errors"
"fmt"
"github.com/Songmu/prompter"
"github.com/kawana77b/ghq-ex/cmd/cmdutil"
"github.com/logrusorgru/aurora/v4"
"github.com/spf13/cobra"
)
// removeCmd represents the remove command
var removeCmd = &cobra.Command{
Use: "remove",
Short: "Remove the repository given as a selection or argument",
Long: ``,
Args: cobra.MatchAll(cobra.MaximumNArgs(1)),
RunE: runRemove,
}
func init() {
rootCmd.AddCommand(removeCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// removeCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// removeCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
func runRemove(cmd *cobra.Command, args []string) error {
g, err := cmdutil.MustGetGhq()
if err != nil {
return err
}
name, err := cmdutil.GetRepositoryName(g, args)
if err != nil {
return err
}
repo := g.Find(name)
if repo == nil {
return errors.New("repository not found")
}
fmt.Printf("You are trying to DELETE this local repository:\n")
fmt.Println(aurora.Sprintf(aurora.Cyan("\t\t%s\n"), repo.Name()))
isYes := prompter.YN("Are you sure?", false)
if !isYes {
return nil
}
if err := repo.Remove(); err != nil {
return err
}
if err := g.Cleanup(); err != nil {
return err
}
fmt.Println()
fmt.Printf("Remove %s\n", repo.Name())
return nil
}