-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1410 from DiceDB/arpit-config-v2
Configuration v2 - Simple, Readable, and Consistent
- Loading branch information
Showing
48 changed files
with
641 additions
and
1,988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ pnpm-debug.log* | |
|
||
# macOS-specific files | ||
.DS_Store | ||
dicedb.yaml | ||
dicedb.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2022-present, DiceDB contributors | ||
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dicedb/dice/config" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var initConfigCmd = &cobra.Command{ | ||
Use: "init-config", | ||
Short: "creates a config file at dicedb.yaml with default values", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config.Init(cmd.Flags()) | ||
_ = viper.WriteConfigAs("dicedb.yaml") | ||
fmt.Println("config created at dicedb.yaml") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(initConfigCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2022-present, DiceDB contributors | ||
// All rights reserved. Licensed under the BSD 3-Clause License. See LICENSE file in the project root for full license information. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"reflect" | ||
"strconv" | ||
|
||
"github.com/dicedb/dice/config" | ||
"github.com/dicedb/dice/server" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
c := config.DiceDBConfig{} | ||
_type := reflect.TypeOf(c) | ||
for i := 0; i < _type.NumField(); i++ { | ||
field := _type.Field(i) | ||
yamlTag := field.Tag.Get("mapstructure") | ||
descriptionTag := field.Tag.Get("description") | ||
defaultTag := field.Tag.Get("default") | ||
|
||
switch field.Type.Kind() { | ||
case reflect.String: | ||
rootCmd.PersistentFlags().String(yamlTag, defaultTag, descriptionTag) | ||
case reflect.Int: | ||
val, _ := strconv.Atoi(defaultTag) | ||
rootCmd.PersistentFlags().Int(yamlTag, val, descriptionTag) | ||
case reflect.Bool: | ||
val, _ := strconv.ParseBool(defaultTag) | ||
rootCmd.PersistentFlags().Bool(yamlTag, val, descriptionTag) | ||
} | ||
} | ||
} | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "dicedb", | ||
Short: "an in-memory database;", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
config.Init(cmd.Flags()) | ||
server.Init() | ||
server.Start() | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.