-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.go
58 lines (50 loc) · 1.7 KB
/
info.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 main
import (
"fmt"
"github.com/mateothegreat/go-multilog/multilog"
"github.com/polyrepopro/polyrepo/util"
"github.com/spf13/cobra"
)
func init() {
infoCommand.Flags().StringSliceP("workspace", "w", []string{}, "the name of the workspace(s) to get info for")
infoCommand.Flags().StringSliceP("tag", "t", []string{}, "the tags to filter the repositories by")
root.AddCommand(infoCommand)
}
var infoCommand = &cobra.Command{
Use: "info",
Short: "Get information about the current workspace.",
Long: "Get information about the current workspace.",
Run: func(cmd *cobra.Command, args []string) {
setup, err := Setup("workspace.commit", "", util.GetArg[string](cmd, "config"))
if err != nil {
multilog.Fatal("workspace.commit", "failed to setup", map[string]interface{}{
"error": err,
})
}
workspaces, err := setup.Config.GetWorkspaces(util.GetArg[[]string](cmd, "workspace"))
if err != nil {
multilog.Fatal("workspace.commit", "failed to get workspaces", map[string]interface{}{
"error": err,
})
}
multilog.Info("config", "located", map[string]interface{}{
"path": setup.Config.Path,
})
for _, workspace := range *workspaces {
repos := workspace.GetRepositories(util.GetArg[[]string](cmd, "tag"))
multilog.Info("workspace", workspace.Name, map[string]interface{}{
"path": workspace.Path,
"repositories": len(*workspace.Repositories),
"tags": workspace.Tags,
})
for _, repo := range *repos {
multilog.Info("workspace.repositories", fmt.Sprintf("%s:%s", workspace.Name, repo.Name), map[string]interface{}{
"url": repo.URL,
"branch": repo.Branch,
"path": repo.Path,
"origin": repo.Origin,
})
}
}
},
}