Skip to content

Commit cb5d1da

Browse files
theckmanjirfag
authored andcommitted
Add support for home directory expansion for -c/--config flag
This change introduces the ability to use the tilde (`~`) character in your `-c/--config` flag value to expand your home directory. If invoking this via the command line with `--config ~/.golangci-lint.yaml`, the user's shell expands the `~` to the home directory. However, if something is invoking the program for you (like an editor) it may not do the expansion. Fixes #289 Signed-off-by: Tim Heckman <t@heckman.io>
1 parent 898ae4d commit cb5d1da

File tree

8 files changed

+205
-0
lines changed

8 files changed

+205
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ require (
4545
github.com/magiconair/properties v1.7.6 // indirect
4646
github.com/mattn/go-colorable v0.0.9
4747
github.com/mattn/go-isatty v0.0.3 // indirect
48+
github.com/mitchellh/go-homedir v1.0.0
4849
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
4950
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238 // indirect
5051
github.com/nbutton23/zxcvbn-go v0.0.0-20171102151520-eafdab6b0663 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU
9595
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
9696
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
9797
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
98+
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
99+
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
98100
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936 h1:kw1v0NlnN+GZcU8Ma8CLF2Zzgjfx95gs3/GN3vYAPpo=
99101
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk=
100102
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238 h1:+MZW2uvHgN8kYvksEN3f7eFL2wpzk0GxmlFsMybWc7E=

pkg/config/reader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111

1212
"github.com/golangci/golangci-lint/pkg/fsutils"
1313
"github.com/golangci/golangci-lint/pkg/logutils"
14+
15+
"github.com/mitchellh/go-homedir"
1416
)
1517

1618
type FileReader struct {
@@ -183,5 +185,10 @@ func (r *FileReader) parseConfigOption() (string, error) {
183185
return "", errConfigDisabled
184186
}
185187

188+
configFile, err := homedir.Expand(configFile)
189+
if err != nil {
190+
return "", fmt.Errorf("failed to expand configuration path")
191+
}
192+
186193
return configFile, nil
187194
}

vendor/github.com/mitchellh/go-homedir/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/mitchellh/go-homedir/README.md

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/mitchellh/go-homedir/go.mod

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/mitchellh/go-homedir/homedir.go

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ github.com/magiconair/properties
135135
github.com/mattn/go-colorable
136136
# github.com/mattn/go-isatty v0.0.3
137137
github.com/mattn/go-isatty
138+
# github.com/mitchellh/go-homedir v1.0.0
139+
github.com/mitchellh/go-homedir
138140
# github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
139141
github.com/mitchellh/go-ps
140142
# github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238

0 commit comments

Comments
 (0)