Skip to content

Commit b76567b

Browse files
committed
Ensure that reading from symlink config files works
1 parent 57c71b6 commit b76567b

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Diff for: .polylint

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
examples/simple.yaml

Diff for: TODO.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@
3838
- [ ] Colored output
3939
- [ ] JSON reporter
4040
- [ ] Configurable logging (log levels for debugging and k/v log values)
41+
- [ ] Add `init` command to create a default named config file

Diff for: cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func initConfig() {
6161
cobra.CheckErr(err)
6262

6363
// Search config in home directory with name ".polylint" (without extension).
64+
viper.AddConfigPath(".")
6465
viper.AddConfigPath(home)
6566
viper.SetConfigType("yaml")
6667
viper.SetConfigName(".polylint")

Diff for: cmd/run.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111

1212
"github.com/spf13/cobra"
13+
"github.com/spf13/viper"
1314
pl "github.com/zph/polylint/pkg"
1415
)
1516

@@ -32,7 +33,13 @@ func Run(cmd *cobra.Command, args []string) (int, []error) {
3233
exitCode = 0
3334
var errs []error
3435
for _, root := range args {
35-
configRaw, err := os.ReadFile(cfgFile)
36+
// Resolve symlinks
37+
s, err := os.Readlink(viper.ConfigFileUsed())
38+
if err == nil {
39+
cfgFile = s
40+
}
41+
configRaw, err := os.ReadFile(viper.ConfigFileUsed())
42+
3643
if err != nil {
3744
panic(err)
3845
}
@@ -90,7 +97,6 @@ func RunCmd(cmd *cobra.Command, args []string) {
9097
exitCode, errs := Run(cmd, args)
9198
if len(errs) > 0 {
9299
fmt.Printf("Errors: %+v", errs)
93-
panic(errs)
94100
}
95101
os.Exit(exitCode)
96102
}

0 commit comments

Comments
 (0)