-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
64 lines (52 loc) · 1.97 KB
/
root.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
package main
import (
"os"
"github.com/pgavlin/dawn/cmd/dawn/internal/term"
"github.com/spf13/cobra"
)
var prof = &profiler{}
var work = &workspace{}
var version = "development"
var termWidth int
var rootCmd = &cobra.Command{
Version: version,
Use: "dawn",
Short: "dawn is a pragmatic polyglot build system.",
Long: `A pragmatic polyglot build system.`,
Args: cobra.ArbitraryArgs,
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
termWidth, _, _ = term.GetSize(os.Stdout)
if cmd.Use != "init" {
if err := work.init(); err != nil {
return err
}
}
return prof.start()
},
RunE: buildCmd.RunE,
PersistentPostRunE: func(_ *cobra.Command, _ []string) error {
return prof.stop()
},
}
func init() {
rootCmd.PersistentFlags().StringVar(&prof.cpuPath, "cpuprofile", "", "write a CPU profile to the given path")
rootCmd.PersistentFlags().StringVar(&prof.starPath, "profile", "", "write an execution profile to the given path")
rootCmd.PersistentFlags().StringVar(&prof.tracePath, "trace", "", "write a runtime trace to the given path")
rootCmd.PersistentFlags().MarkHidden("cpuprofile")
rootCmd.PersistentFlags().MarkHidden("trace")
rootCmd.PersistentFlags().BoolVarP(&work.reindex, "reindex", "r", false, "refresh the project's index")
rootCmd.Flags().BoolVarP(&buildOptions.Always, "always", "B", false, "consider all targets out-of-date")
rootCmd.Flags().BoolVarP(&buildOptions.DryRun, "dry-run", "n", false, "print the targets that would be built, but do not build them")
rootCmd.Flags().StringVar(&buildJSON, "json", "", "write JSON build events to the given path")
rootCmd.PersistentFlags().SetInterspersed(false)
rootCmd.Flags().SetInterspersed(false)
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(buildCmd)
rootCmd.AddCommand(watchCmd)
rootCmd.AddCommand(replCmd)
rootCmd.AddCommand(listCmd)
rootCmd.AddCommand(gcCmd)
rootCmd.AddCommand(completionCmd)
rootCmd.SetHelpCommand(helpCmd)
}