Skip to content

Commit

Permalink
fixing minor issues releted args out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
vinitparekh17 committed Nov 22, 2024
1 parent 1eb4571 commit c1f5cd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,22 @@ func loadDiceConfig(configFilePath string) error {
return parser.Loadconfig(DiceConfig)
}

func ManageSubCommandActions(version bool, flagsConfig *Config) {
func ManageSubCommandActions(version bool, flagsConfig *Config) bool {
if version {
showDiceDBVersion()
}

if CustomConfigFilePath != utils.EmptyStr {
parseCustomConfigFile(flagsConfig, CustomConfigFilePath)
return true
}

if CustomConfigDirPath != utils.EmptyStr {
saveConfigFileAtSpecifiedPath(flagsConfig, CustomConfigDirPath)
return true
}

return false
}

func showDiceDBVersion() {
Expand Down
11 changes: 6 additions & 5 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func printConfiguration() {

// printConfigTable prints key-value pairs in a vertical table format.
func render() {
color.Set(color.FgHiRed)
fmt.Print(`
██████╗ ██╗ ██████╗███████╗██████╗ ██████╗
██╔══██╗██║██╔════╝██╔════╝██╔══██╗██╔══██╗
Expand All @@ -64,7 +63,6 @@ func render() {
╚═════╝ ╚═╝ ╚═════╝╚══════╝╚═════╝ ╚═════╝
`)
color.Unset()
printConfiguration()
}

Expand Down Expand Up @@ -140,21 +138,24 @@ func Execute() {
}

flag.Parse()
config.ManageSubCommandActions(version, &flagsConfig)
if ok := config.ManageSubCommandActions(version, &flagsConfig); ok {
render()
}

// this subcommand is used to read the config file values from the stdin i.e echo 'resp_server.port="8888"' | ./dicedb -
if os.Args[1] == "-" {
if len(os.Args) == 2 && os.Args[1] == "-" {
parser := config.NewConfigParser()
if err := parser.ParseFromStdin(); err != nil {
log.Fatal(err)
}
if err := parser.Loadconfig(config.DiceConfig); err != nil {
log.Fatal(err)
}
slog.Info("config file loaded from stdin")
render()
slog.Info("config file loaded from stdin")
} else {
defaultConfig(&flagsConfig)
render()
}
}

Expand Down

0 comments on commit c1f5cd4

Please sign in to comment.