-
Notifications
You must be signed in to change notification settings - Fork 0
/
repos_add.go
56 lines (42 loc) · 1.16 KB
/
repos_add.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
package cmd
import (
"fmt"
"log"
"github.com/repowarden/cli/warden/vcsurl"
"github.com/spf13/cobra"
)
var (
reposAddCmd = &cobra.Command{
Use: "add",
Short: "Add a repository to 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(groupFl)
if err != nil {
return err
}
group.Add(RepositoryDefinition{URL: repository})
filepath, err := repositoriesFile.save(repositoriesFileFl, false)
if err != nil {
return err
}
fmt.Printf("The repositories file %s has been created/updated.", filepath)
return nil
},
}
)
func init() {
reposAddCmd.PersistentFlags().StringVar(&groupFl, "group", "", "which group the repository belongs to")
reposAddCmd.MarkFlagRequired("group")
AddRepositoriesFileFlag(reposAddCmd)
reposCmd.AddCommand(reposAddCmd)
}