-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
124 lines (113 loc) · 3.2 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"github.com/alaingilbert/git2graph/git2graph"
"os"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func startAction(c *cli.Context) error {
var nodes []*git2graph.Node
var err error
fromFlag := c.String("from")
limitFlag := c.Int("limit")
//contextFlag := c.Bool("context")
jsonFlag := c.String("json")
fileFlag := c.String("file")
repoFlag := c.Bool("repo")
topoOrderFlag := c.Bool("topo-order")
dateOrderFlag := c.Bool("date-order")
git2graph.NoOutput = c.Bool("no-output")
repoLinearFlag := c.Bool("repo-linear")
seqIds := c.Bool("seq-ids")
rowsFlag := c.Bool("rows")
logLevel := c.String("log")
setLogLevel(logLevel)
if repoFlag || repoLinearFlag {
order := git2graph.DefaultOrder
if topoOrderFlag {
order = git2graph.TopoOrder
} else if dateOrderFlag {
order = git2graph.DateOrder
}
if seqIds {
nodes, err = git2graph.GetInputNodesFromRepoSeq("", order, limitFlag)
} else {
nodes, err = git2graph.GetInputNodesFromRepo("", order, limitFlag)
}
if repoLinearFlag {
git2graph.SerializeOutput(&git2graph.Out{Nodes: nodes})
return err
}
} else if jsonFlag != "" {
nodes, err = git2graph.GetInputNodesFromJSON([]byte(jsonFlag))
} else if fileFlag != "" {
nodes, err = git2graph.GetInputNodesFromFile(fileFlag)
} else {
return cli.ShowAppHelp(c)
}
if err != nil {
log.Error(err)
return err
}
var out *git2graph.Out
if rowsFlag {
out, err = git2graph.GetPaginatedRows(nodes, fromFlag, limitFlag)
} else {
out, err = git2graph.GetPaginated(nodes, fromFlag, limitFlag)
}
if err != nil {
log.Error(err)
return err
}
git2graph.SerializeOutput(out)
return err
}
func setLogLevel(logLevel string) {
switch logLevel {
case "debug":
log.SetLevel(log.DebugLevel)
case "info":
log.SetLevel(log.InfoLevel)
case "warn":
log.SetLevel(log.WarnLevel)
case "error":
log.SetLevel(log.ErrorLevel)
case "fatal":
log.SetLevel(log.FatalLevel)
case "panic":
log.SetLevel(log.PanicLevel)
default:
log.SetLevel(log.WarnLevel)
}
}
func init() {
log.SetLevel(log.WarnLevel)
}
func main() {
var authors []cli.Author
// Collaborators, add your name here :)
authors = append(authors, cli.Author{Name: "Alain Gilbert", Email: "alain.gilbert.15@gmail.com"})
app := cli.NewApp()
app.Authors = authors
app.Version = "0.0.0"
app.Name = "git2graph"
app.Usage = "Take a git tree, make a graph structure"
app.Flags = []cli.Flag{
cli.StringFlag{Name: "f, file", Usage: "File"},
cli.StringFlag{Name: "j, json", Usage: "Json input"},
cli.StringFlag{Name: "L, log", Usage: "Log level"},
cli.BoolFlag{Name: "r, repo", Usage: "Repository"},
cli.BoolFlag{Name: "topo-order", Usage: "Topological order"},
cli.BoolFlag{Name: "l, repo-linear", Usage: "Repository linear history"},
cli.BoolFlag{Name: "s, seq-ids", Usage: "Use sequential ids instead of sha for linear history"},
cli.BoolFlag{Name: "n, no-output", Usage: "No output"},
cli.BoolFlag{Name: "rows", Usage: "Rows graph"},
cli.StringFlag{Name: "from", Usage: "From"},
cli.IntFlag{Name: "limit", Usage: "Limit", Value: -1},
cli.BoolFlag{Name: "context", Usage: "Include context"},
}
app.Action = startAction
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}