-
Notifications
You must be signed in to change notification settings - Fork 19
/
describe-gitinfo.go
53 lines (48 loc) · 1.14 KB
/
describe-gitinfo.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
package cmd
import (
"github.com/gitpod-io/leeway/pkg/leeway"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// describeGitInfoCmd represents the describeTree command
var describeGitInfoCmd = &cobra.Command{
Use: "git-info",
Short: "Prints the Git info consumed by leeway",
Run: func(cmd *cobra.Command, args []string) {
comp, pkg, script, _ := getTarget(args, false)
var (
nfo *leeway.GitInfo
loc string
)
if comp != nil {
nfo = comp.Git()
loc = comp.Origin
} else if pkg != nil {
nfo = pkg.C.Git()
loc = pkg.C.Origin
} else if script != nil {
nfo = script.C.Git()
loc = script.C.Origin
} else {
log.Fatal("no target given - try passing a package or component")
}
if nfo == nil {
log.WithField("loc", loc).Fatal("not a Git working copy")
}
w := getWriterFromFlags(cmd)
if w.FormatString == "" {
w.FormatString = `dirty: {{.Dirty }}
origin: {{ .Origin }}
commit: {{ .Commit }}
`
}
err := w.Write(nfo)
if err != nil {
log.WithError(err).Fatal("cannot write git info")
}
},
}
func init() {
describeCmd.AddCommand(describeGitInfoCmd)
addFormatFlags(describeGitInfoCmd)
}