forked from dgraph-io/dgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
88 lines (80 loc) · 2.79 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (C) 2017 Dgraph Labs, Inc. and Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"fmt"
"os"
"runtime"
"github.com/dgraph-io/dgraph/dgraph/cmd/bulk"
"github.com/dgraph-io/dgraph/dgraph/cmd/live"
"github.com/dgraph-io/dgraph/dgraph/cmd/server"
"github.com/dgraph-io/dgraph/dgraph/cmd/zero"
"github.com/dgraph-io/dgraph/x"
"github.com/pkg/profile"
"github.com/spf13/cobra"
)
var profileMode string
var blockRate int
var version bool
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "dgraph",
Short: "Dgraph: Distributed Graph Database",
Long: `
Dgraph is an open source, horizontally scalable and distributed graph database,
providing ACID transactions, consistent replication and linearizable reads.
It's built from ground up to perform for a rich set of queries. Being a native
graph database, it tightly controls how the data is arranged on disk to optimize
for query performance and throughput, reducing disk seeks and network calls in a
cluster.
` + x.BuildDetails(),
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
switch profileMode {
case "cpu":
defer profile.Start(profile.CPUProfile).Stop()
case "mem":
defer profile.Start(profile.MemProfile).Stop()
case "mutex":
defer profile.Start(profile.MutexProfile).Stop()
case "block":
runtime.SetBlockProfileRate(blockRate)
defer profile.Start(profile.BlockProfile).Stop()
case "":
// do nothing
default:
fmt.Printf("Invalid profile mode: %q\n", profileMode)
os.Exit(1)
}
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize()
RootCmd.AddCommand(bulk.BulkCmd)
RootCmd.AddCommand(live.LiveCmd)
RootCmd.AddCommand(server.ServerCmd)
RootCmd.AddCommand(zero.ZeroCmd)
RootCmd.PersistentFlags().StringVar(&profileMode, "profile.mode", "",
"Enable profiling mode, one of [cpu, mem, mutex, block]")
RootCmd.PersistentFlags().IntVar(&blockRate, "block.rate", 0,
"Block profiling rate. Must be used along with block profile.mode")
}