forked from iangrunert/git-ratchet
/
git-ratchet.go
95 lines (79 loc) · 2.94 KB
/
git-ratchet.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
package main
import (
ratchet "github.com/iangrunert/git-ratchet/cmd"
"github.com/spf13/cobra"
log "github.com/spf13/jwalterweatherman"
"os"
"fmt"
)
var GitTag string // Will be passed to the compiler by scripts/build.sh
func main() {
var write bool
var verbose bool
var prefix string
var slack int
var inputType string
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Long: `All software has versions.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("git-ratchet version: %s\n", GitTag)
},
}
var checkCmd = &cobra.Command{
Use: "check",
Short: "Checks the values passed in against the most recent stored values.",
Long: `Checks the values passed in against the most recent stored values.
The most recent stored values are found by walking up the commit graph and looking at the git-notes stored.`,
Run: func(cmd *cobra.Command, args []string) {
if verbose {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
err := ratchet.Check(prefix, slack, write, inputType, os.Stdin)
if err != 0 {
os.Exit(err)
}
},
}
checkCmd.Flags().BoolVarP(&write, "write", "w", false, "write values if no increase is detected. only use on your CI server.")
checkCmd.Flags().IntVarP(&slack, "slack", "s", 0, "slack value, increase within the range of the slack is acceptable.")
checkCmd.Flags().StringVarP(&inputType, "inputType", "i", "csv", "input type. csv and checkstyle available.")
var measure string
var excuse string
var excuseCmd = &cobra.Command{
Use: "excuse",
Short: "Write an excuse for a measurement increase.",
Long: `Write an excuse for a measurement increase. This will allow the check command to pass.`,
Run: func(cmd *cobra.Command, args []string) {
if verbose {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
os.Exit(ratchet.Excuse(prefix, measure, excuse))
},
}
excuseCmd.Flags().StringVarP(&measure, "name", "n", "", "names of the measures to excuse, comma separated list.")
excuseCmd.Flags().StringVarP(&excuse, "excuse", "e", "", "excuse for the measure rising.")
var dumpCmd = &cobra.Command{
Use: "dump",
Short: "Dump a CSV file containing the measurement data over time.",
Long: `Dump a CSV file containing the measurement data over time.`,
Run: func(cmd *cobra.Command, args []string) {
if verbose {
log.SetLogThreshold(log.LevelInfo)
log.SetStdoutThreshold(log.LevelInfo)
}
err := ratchet.Dump(prefix, os.Stdout)
if err != 0 {
os.Exit(err)
}
},
}
var rootCmd = &cobra.Command{Use: "git-ratchet"}
rootCmd.AddCommand(checkCmd, excuseCmd, dumpCmd, versionCmd)
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "increase logging verbosity.")
rootCmd.PersistentFlags().StringVarP(&prefix, "prefix", "p", "master", "prefix the ratchet notes. useful for storing multiple sets of values in the same repo.")
rootCmd.Execute()
}