From c3fe265e111d8d15f77d572fff7cbf9dad1ad9a7 Mon Sep 17 00:00:00 2001 From: Karl Dreher Date: Wed, 26 Mar 2025 19:10:57 -0700 Subject: [PATCH 1/3] fix: fail when config file not found --- cmd/root.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/root.go b/cmd/root.go index 799c1c8..c3d414a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -85,6 +85,10 @@ func initConfig() { if cfgFile != "" { // Use config file from the flag. viper.SetConfigFile(cfgFile) + _, err := os.Stat(cfgFile) + // If the specified file does not exist, fail. + cobra.CheckErr(err) + } else { // Find home directory. home, err := os.UserHomeDir() From 3d45a0f772ebbe4cddc39228f4e7866e95a5dfb9 Mon Sep 17 00:00:00 2001 From: Karl Dreher Date: Wed, 26 Mar 2025 19:18:48 -0700 Subject: [PATCH 2/3] feat: search path starting at cwd --- cmd/root.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index c3d414a..e42b39a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -90,14 +90,24 @@ func initConfig() { cobra.CheckErr(err) } else { + // use the working directory as a primary search path + pwd, err := os.Getwd() + cobra.CheckErr(err) // Find home directory. home, err := os.UserHomeDir() cobra.CheckErr(err) - // Search config in home directory with name ".fmlint.yaml" + // Search directories for a config file. + // The first added paths take precedence. + viper.AddConfigPath(pwd) viper.AddConfigPath(home) + viper.SetConfigType("yaml") viper.SetConfigName(".fmlint") + // when the config file is found, print it + if viper.ConfigFileUsed() != "" { + fmt.Printf("Config file name: %s\n", viper.ConfigFileUsed()) + } } viper.AutomaticEnv() // read in environment variables that match From 628d63ef90eb872f59da0b712d4dc416ec9ddc0c Mon Sep 17 00:00:00 2001 From: Karl Dreher Date: Wed, 26 Mar 2025 19:23:50 -0700 Subject: [PATCH 3/3] ci: skip linting on main --- .github/workflows/cicd.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 7a1018d..60779b0 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -8,6 +8,8 @@ on: - '**' jobs: lint: + # no need to lint on main + if: github.ref != 'refs/heads/main' runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4