Skip to content

Commit

Permalink
feat: use .nwa-config.yaml as default config file
Browse files Browse the repository at this point in the history
  • Loading branch information
justlorain committed Jan 27, 2025
1 parent e55f7fe commit 67ecf60
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ nwa:
skip: ["**/*.py"]
`,
GroupID: _config,
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if err := defaultConfig.readInConfig(args[0]); err != nil {
if err := defaultConfig.readInConfig(args); err != nil {
cobra.CheckErr(err)
}

Expand Down Expand Up @@ -177,8 +177,16 @@ var defaultConfig = &Config{Nwa: NwaConfig{
RawTmpl: "",
}}

func (cfg *Config) readInConfig(path string) error {
viper.SetConfigFile(path)
func (cfg *Config) readInConfig(args []string) error {
if len(args) == 0 {
// default configuration path: ./.nwa-config.yaml
viper.SetConfigName(".nwa-config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
} else {
viper.SetConfigFile(args[0])
}

if err := viper.ReadInConfig(); err != nil {
return err
}
Expand Down

0 comments on commit 67ecf60

Please sign in to comment.