Skip to content

Commit

Permalink
Merge pull request #214 from twpayne/xdg
Browse files Browse the repository at this point in the history
Use latest github.com/twpayne/go-xdg
  • Loading branch information
twpayne committed Feb 21, 2019
2 parents 1e7307d + ab1de29 commit abc7f6f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
20 changes: 10 additions & 10 deletions cmd/config.go
Expand Up @@ -244,18 +244,18 @@ func (c *Config) runEditor(argv ...string) error {
return c.run("", c.getEditor(), argv...)
}

func getDefaultConfigFile(x *xdg.XDG) string {
// Search XDG config directories first.
for _, configDir := range x.ConfigDirs {
func getDefaultConfigFile(bds *xdg.BaseDirectorySpecification) string {
// Search XDG Base Directory Specification config directories first.
for _, configDir := range bds.ConfigDirs {
for _, extension := range viper.SupportedExts {
configFilePath := filepath.Join(configDir, "chezmoi", "chezmoi."+extension)
if _, err := os.Stat(configFilePath); err == nil {
return configFilePath
}
}
}
// Fallback to XDG default.
return filepath.Join(x.ConfigHome, "chezmoi", "chezmoi.yaml")
// Fallback to XDG Base Directory Specification default.
return filepath.Join(bds.ConfigHome, "chezmoi", "chezmoi.yaml")
}

func getDefaultData(fs vfs.FS) (map[string]interface{}, error) {
Expand Down Expand Up @@ -308,16 +308,16 @@ func getDefaultData(fs vfs.FS) (map[string]interface{}, error) {
return data, nil
}

func getDefaultSourceDir(x *xdg.XDG) string {
// Check for XDG data directories first.
for _, dataDir := range x.DataDirs {
func getDefaultSourceDir(bds *xdg.BaseDirectorySpecification) string {
// Check for XDG Base Directory Specification data directories first.
for _, dataDir := range bds.DataDirs {
sourceDir := filepath.Join(dataDir, "chezmoi")
if _, err := os.Stat(sourceDir); err == nil {
return sourceDir
}
}
// Fallback to XDG default.
return filepath.Join(x.DataHome, "chezmoi")
// Fallback to XDG Base Directory Specification default.
return filepath.Join(bds.DataHome, "chezmoi")
}

// isWellKnownAbbreviation returns true if word is a well known abbreviation.
Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Expand Up @@ -40,19 +40,19 @@ func init() {
printErrorAndExit(err)
}

x, err := xdg.NewXDG()
bds, err := xdg.NewBaseDirectorySpecification()
if err != nil {
printErrorAndExit(err)
}

persistentFlags := rootCmd.PersistentFlags()

persistentFlags.StringVarP(&config.configFile, "config", "c", getDefaultConfigFile(x), "config file")
persistentFlags.StringVarP(&config.configFile, "config", "c", getDefaultConfigFile(bds), "config file")

persistentFlags.BoolVarP(&config.DryRun, "dry-run", "n", false, "dry run")
viper.BindPFlag("dry-run", persistentFlags.Lookup("dry-run"))

persistentFlags.StringVarP(&config.SourceDir, "source", "S", getDefaultSourceDir(x), "source directory")
persistentFlags.StringVarP(&config.SourceDir, "source", "S", getDefaultSourceDir(bds), "source directory")
viper.BindPFlag("source", persistentFlags.Lookup("source"))

persistentFlags.StringVarP(&config.DestDir, "destination", "D", homeDir, "destination directory")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -20,7 +20,7 @@ require (
github.com/stretchr/objx v0.1.1 // indirect
github.com/twpayne/go-shell v0.0.1
github.com/twpayne/go-vfs v1.0.4
github.com/twpayne/go-xdg v1.0.0
github.com/twpayne/go-xdg v0.0.0-20190220233246-4973c34fec2f
github.com/zalando/go-keyring v0.0.0-20180221093347-6d81c293b3fb
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
gopkg.in/yaml.v2 v2.2.2
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Expand Up @@ -15,6 +15,7 @@ github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt
github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/danieljoos/wincred v1.0.1 h1:fcRTaj17zzROVqni2FiToKUVg3MmJ4NtMSGCySPIr/g=
github.com/danieljoos/wincred v1.0.1/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
Expand All @@ -35,8 +36,6 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
Expand All @@ -55,17 +54,20 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/twpayne/go-shell v0.0.1 h1:Ako3cUeuULhWadYk37jM3FlJ8lkSSW4INBjYj9K60Gw=
github.com/twpayne/go-shell v0.0.1/go.mod h1:QCjEvdZndTuPObd+11NYAI1UeNLSuGZVxJ+67Wl+IU4=
github.com/twpayne/go-vfs v0.1.5/go.mod h1:OIXA6zWkcn7Jk46XT7ceYqBMeIkfzJ8WOBhGJM0W4y8=
github.com/twpayne/go-vfs v1.0.4 h1:sPmifWt4KGVXk0ZyHbtTRANu+L6BuZLNDF2H7W/qXT8=
github.com/twpayne/go-vfs v1.0.4/go.mod h1:OIXA6zWkcn7Jk46XT7ceYqBMeIkfzJ8WOBhGJM0W4y8=
github.com/twpayne/go-xdg v1.0.0 h1:k+QM2LL00/zx/gvxKsCMRBJ8nxCBWDBe2LU9y3Xo7x0=
github.com/twpayne/go-xdg v1.0.0/go.mod h1:SHOoqWXTQT0rcQM4isbONZ6bH6uwIBgXuymEVgTc+Ao=
github.com/twpayne/go-xdg v0.0.0-20190220233246-4973c34fec2f h1:uYmFQ0IrWCECHYQl+uNqThrKu91ZBqRYbKH/ayY8u7U=
github.com/twpayne/go-xdg v0.0.0-20190220233246-4973c34fec2f/go.mod h1:XO3i+LkLxZIz6VmOkre/w8m0en5znGMlZIg0yOHtbFs=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/zalando/go-keyring v0.0.0-20180221093347-6d81c293b3fb h1:tXbazu9ZlecQbyCczvA22mWj+lw/36Bdwxapk8v7e7s=
Expand Down

0 comments on commit abc7f6f

Please sign in to comment.