-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos_rm.go
58 lines (44 loc) · 1.13 KB
/
repos_rm.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
package cmd
import (
"fmt"
"log"
"github.com/repowarden/cli/warden/vcsurl"
"github.com/spf13/cobra"
)
var (
reposRMCmd = &cobra.Command{
Use: "rm",
Short: "Remove a repository from the repositories.yml file",
RunE: func(cmd *cobra.Command, args []string) error {
repository := args[0]
// ensure the repository URL is valid
_, err := vcsurl.Parse(repository)
if err != nil {
return fmt.Errorf("The repository URL %s is invalid: %s", repository, err)
}
repositoriesFile, _, err := loadRepositoriesFile(repositoriesFileFl)
if err != nil {
log.Fatal(err)
}
group, err := repositoriesFile.Group("all")
if err != nil {
return err
}
removed := group.Remove(RepositoryDefinition{URL: repository})
if !removed {
fmt.Println("No change was made. Couldn't find repository.")
return nil
}
filepath, err := repositoriesFile.save(repositoriesFileFl, false)
if err != nil {
return err
}
fmt.Printf("The repositories file %s has been updated.", filepath)
return nil
},
}
)
func init() {
AddRepositoriesFileFlag(reposRMCmd)
reposCmd.AddCommand(reposRMCmd)
}