Skip to content

Commit

Permalink
Opt: remove custom config file
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Nov 28, 2023
1 parent 34ae720 commit 9471721
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 0 additions & 2 deletions cmd/flags/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ var (

LogStd bool

ConfigFile string

SkipEnv bool

SkipConfig bool
Expand Down
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func init() {
home = "~"
}
RootCmd.PersistentFlags().StringVar(&flags.DataDir, "data-dir", filepath.Join(home, ".synctv"), "data dir")
RootCmd.PersistentFlags().StringVarP(&flags.ConfigFile, "config", "f", "", "config file path")
}

func init() {
Expand Down
16 changes: 6 additions & 10 deletions internal/bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ func InitConfig(ctx context.Context) (err error) {
}
conf.Conf = conf.DefaultConfig()
if !flags.SkipConfig {
if flags.ConfigFile == "" {
flags.ConfigFile = filepath.Join(flags.DataDir, "config.yaml")
} else {
flags.ConfigFile, err = utils.OptFilePath(flags.ConfigFile)
if err != nil {
log.Fatalf("config file path error: %v", err)
}
configFile, err := utils.OptFilePath(filepath.Join(flags.DataDir, "config.yaml"))
if err != nil {
log.Fatalf("config file path error: %v", err)
}
err = confFromConfig(flags.ConfigFile, conf.Conf)
err = confFromConfig(configFile, conf.Conf)
if err != nil {
log.Fatalf("load config from file error: %v", err)
}
log.Infof("load config success from file: %s", flags.ConfigFile)
if err = restoreConfig(flags.ConfigFile, conf.Conf); err != nil {
log.Infof("load config success from file: %s", configFile)
if err = restoreConfig(configFile, conf.Conf); err != nil {
log.Warnf("restore config error: %v", err)
} else {
log.Info("restore config success")
Expand Down

0 comments on commit 9471721

Please sign in to comment.