()
| 121 | func (pFlag) Type() string { return "string" } |
| 122 | |
| 123 | func 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() |
nothing calls this directly
no test coverage detected