MCPcopy
hub / github.com/cayleygraph/cayley / init

Function init

cmd/cayley/cayley.go:123–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

121func (pFlag) Type() string { return "string" }
122
123func init() {
124 // set config names and paths
125 viper.SetConfigName("cayley")
126 viper.SetEnvPrefix("cayley")
127 viper.AddConfigPath(".")
128 viper.AddConfigPath("$HOME/.cayley/")
129 viper.AddConfigPath("/etc/")
130 if conf := os.Getenv("CAYLEY_CFG"); conf != "" {
131 viper.SetConfigFile(conf)
132 }
133
134 rootCmd.AddCommand(
135 versionCmd,
136 command.NewInitDatabaseCmd(),
137 command.NewLoadDatabaseCmd(),
138 command.NewDumpDatabaseCmd(),
139 command.NewUpgradeCmd(),
140 command.NewReplCmd(),
141 command.NewQueryCmd(),
142 command.NewHttpCmd(),
143 command.NewConvertCmd(),
144 command.NewDedupCommand(),
145 )
146 rootCmd.PersistentFlags().StringP("config", "c", "", "path to an explicit configuration file")
147
148 qnames := graph.QuadStores()
149 rootCmd.PersistentFlags().StringP("db", "d", "memstore", "database backend to use: "+strings.Join(qnames, ", "))
150 rootCmd.PersistentFlags().StringP("dbpath", "a", "", "path or address string for database")
151 rootCmd.PersistentFlags().Bool("read_only", false, "open database in read-only mode")
152
153 rootCmd.PersistentFlags().Bool("dup", true, "don't stop loading on duplicated on add")
154 rootCmd.PersistentFlags().Bool("missing", false, "don't stop loading on missing key on delete")
155 rootCmd.PersistentFlags().Int("batch", quad.DefaultBatch, "size of quads batch to load at once")
156
157 rootCmd.PersistentFlags().String("memprofile", "", "path to output memory profile")
158 rootCmd.PersistentFlags().String("cpuprofile", "", "path to output cpu profile")
159
160 rootCmd.PersistentFlags().String("pprof", "", "host to serve pprof on (disabled by default)")
161 rootCmd.PersistentFlags().String("metrics", "", "host to serve metrics on (disabled by default)")
162
163 // bind flags to config variables
164 viper.BindPFlag(command.KeyBackend, rootCmd.PersistentFlags().Lookup("db"))
165 viper.BindPFlag(command.KeyAddress, rootCmd.PersistentFlags().Lookup("dbpath"))
166 viper.BindPFlag(command.KeyReadOnly, rootCmd.PersistentFlags().Lookup("read_only"))
167 viper.BindPFlag("load.ignore_duplicates", rootCmd.PersistentFlags().Lookup("dup"))
168 viper.BindPFlag("load.ignore_missing", rootCmd.PersistentFlags().Lookup("missing"))
169 viper.BindPFlag(command.KeyLoadBatch, rootCmd.PersistentFlags().Lookup("batch"))
170
171 // make both store.path and store.address work
172 viper.RegisterAlias(command.KeyPath, command.KeyAddress)
173 // aliases for legacy config files
174 viper.RegisterAlias("database", command.KeyBackend)
175 viper.RegisterAlias("db_path", command.KeyAddress)
176 viper.RegisterAlias("read_only", command.KeyReadOnly)
177 viper.RegisterAlias("db_options", command.KeyOptions)
178
179 { // re-register standard Go flags to cobra
180 rf := rootCmd.PersistentFlags()

Callers

nothing calls this directly

Calls 14

NewInitDatabaseCmdFunction · 0.92
NewLoadDatabaseCmdFunction · 0.92
NewDumpDatabaseCmdFunction · 0.92
NewUpgradeCmdFunction · 0.92
NewReplCmdFunction · 0.92
NewQueryCmdFunction · 0.92
NewHttpCmdFunction · 0.92
NewConvertCmdFunction · 0.92
NewDedupCommandFunction · 0.92
QuadStoresFunction · 0.92
ParseMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected