Skip to content

Commit

Permalink
Do not require config file
Browse files Browse the repository at this point in the history
  • Loading branch information
wizeguyy committed Oct 9, 2024
1 parent 8e9689d commit 9eb9ccd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/go-quai/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ func rootCmdPreRun(cmd *cobra.Command, args []string) error {
viper.SetConfigType(constants.CONFIG_FILE_TYPE)

// Write default config file if it does not exist
if _, err := os.Stat(filepath.Join(configDir, constants.CONFIG_FILE_NAME)); os.IsNotExist(err) {
err := utils.WriteDefaultConfigFile(configDir, constants.CONFIG_FILE_NAME, constants.CONFIG_FILE_TYPE)
if err != nil {
return err
if viper.GetBool(utils.InitConfigFlag.Name) {
if _, err := os.Stat(filepath.Join(configDir, constants.CONFIG_FILE_NAME)); os.IsNotExist(err) {
err := utils.WriteDefaultConfigFile(configDir, constants.CONFIG_FILE_NAME, constants.CONFIG_FILE_TYPE)
if err != nil {
return err
}
log.Global.WithField("path", filepath.Join(configDir, constants.CONFIG_FILE_NAME)).Info("Initialized new config file.")
} else {
log.Global.WithField("path", filepath.Join(configDir, constants.CONFIG_FILE_NAME)).Fatal("Cannot init config file. File already exists. Either remove this option to run with the existing config file, or delete the existing config file to re-initialize a new one.")
}
log.Global.WithField("path", filepath.Join(configDir, constants.CONFIG_FILE_NAME)).Info("Default config file created")
}

// load config from file and environment variables
Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var Flags = [][]Flag{
var GlobalFlags = []Flag{
ConfigDirFlag,
DataDirFlag,
InitConfigFlag,
AncientDirFlag,
LogLevelFlag,
LogSizeFlag,
Expand Down Expand Up @@ -185,6 +186,12 @@ var (
Usage: "data directory" + generateEnvDoc(c_GlobalFlagPrefix+"data-dir"),
}

InitConfigFlag = Flag{
Name: c_GlobalFlagPrefix + "init-cfg",
Value: false,
Usage: "initialize a new config file, if one does not already exist",
}

AncientDirFlag = Flag{
Name: c_GlobalFlagPrefix + "datadir-ancient",
Value: "",
Expand Down

0 comments on commit 9eb9ccd

Please sign in to comment.