Split out Command from Library
This commit is contained in:
21
vendor/github.com/casimir/xdg-go/LICENSE
generated
vendored
Normal file
21
vendor/github.com/casimir/xdg-go/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Martin Chaine
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
33
vendor/github.com/casimir/xdg-go/README.md
generated
vendored
Normal file
33
vendor/github.com/casimir/xdg-go/README.md
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
xdg-go [](https://godoc.org/github.com/casimir/xdg-go) [](https://codebeat.co/projects/github-com-casimir-xdg-go)
|
||||
=======================================================================================================================================================================================================================================
|
||||
|
||||
## Quickstart
|
||||
|
||||
If you just want OS-sensible paths.
|
||||
```
|
||||
configDirs := xdg.ConfigDirs()
|
||||
dataPath := xdg.DataHome()
|
||||
cachePath := xdg.CacheHome()
|
||||
```
|
||||
|
||||
Alternatively you can create a context that would determine full paths for your application files.
|
||||
```
|
||||
app := xdg.App{Name: "someApp"}
|
||||
configFile := app.ConfigPath("someApp.toml")
|
||||
dataFile := app.DataPath("data.json")
|
||||
```
|
||||
|
||||
## Supported path types
|
||||
|
||||
This is a KISS implementation of the XDG Base Directory Specification. As of now it handles the following path types:
|
||||
- Data (`XDG_DATA_*`) for application-wide or user-wide data.
|
||||
- Config (`XDG_CONFIG_*`) for application-wide or user-wide config.
|
||||
- Cache (`XDG_CACHE_*`)for application-wide or user-wide cached data.
|
||||
|
||||
## Multi-OS
|
||||
|
||||
The specification is Linux centric but this implementation targets more: Linux, OSX and Windows. Default values has been chosen regarding both the specification and the OS conventions. Note than you can override these values with the corresponding environment variables.
|
||||
|
||||
There are a lot of OSes missing but supporting them implies a good knowledge of these conventions and philosophies, contributors maybe?
|
||||
|
||||
|
93
vendor/github.com/casimir/xdg-go/xdg.go
generated
vendored
Normal file
93
vendor/github.com/casimir/xdg-go/xdg.go
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
package xdg
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// App is an aggregation of XDG information for a named application. Useful to
|
||||
// propagate app configuration.
|
||||
type App struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (a App) path(envVar string, defaultFn func() string, file string) string {
|
||||
base := os.Getenv(envVar)
|
||||
if base == "" {
|
||||
base = defaultFn()
|
||||
}
|
||||
return filepath.Join(base, a.Name, file)
|
||||
}
|
||||
|
||||
// DataPath determines the full path of a data file.
|
||||
func (a App) DataPath(file string) string {
|
||||
return a.path("XDG_DATA_HOME", DataHome, file)
|
||||
}
|
||||
|
||||
// ConfigPath determines the full path of a data file.
|
||||
func (a App) ConfigPath(file string) string {
|
||||
return a.path("XDG_CONFIG_HOME", ConfigHome, file)
|
||||
}
|
||||
|
||||
// CachePath determines the full path of a cached file.
|
||||
func (a App) CachePath(file string) string {
|
||||
return a.path("XDG_CACHE_HOME", CacheHome, file)
|
||||
}
|
||||
|
||||
func (a App) multiPaths(envVar string, defaultFn func() []string, file string) []string {
|
||||
var bases []string
|
||||
env := os.Getenv(envVar)
|
||||
if env != "" {
|
||||
bases = strings.Split(env, ":")
|
||||
} else {
|
||||
bases = defaultFn()
|
||||
}
|
||||
var dirs []string
|
||||
for _, it := range bases {
|
||||
dirs = append(dirs, filepath.Join(it, a.Name, file))
|
||||
}
|
||||
return dirs
|
||||
}
|
||||
|
||||
// SystemDataPaths determines system-wide possible paths for a data file.
|
||||
func (a App) SystemDataPaths(file string) []string {
|
||||
return a.multiPaths("XDG_DATA_DIRS", DataDirs, file)
|
||||
}
|
||||
|
||||
// SystemConfigPaths determines system-wide possible paths for a config file.
|
||||
func (a App) SystemConfigPaths(file string) []string {
|
||||
return a.multiPaths("XDG_CONFIG_DIRS", ConfigDirs, file)
|
||||
}
|
||||
|
||||
var defaultApp App
|
||||
|
||||
// SetName for the default application. Used for package-wide functions.
|
||||
func SetName(name string) {
|
||||
defaultApp.Name = name
|
||||
}
|
||||
|
||||
// DataPath determines the full path of a data file.
|
||||
func DataPath(file string) string {
|
||||
return defaultApp.DataPath(file)
|
||||
}
|
||||
|
||||
// ConfigPath determines the full path of a data file.
|
||||
func ConfigPath(file string) string {
|
||||
return defaultApp.ConfigPath(file)
|
||||
}
|
||||
|
||||
// CachePath determines the full path of a cached file.
|
||||
func CachePath(file string) string {
|
||||
return defaultApp.CachePath(file)
|
||||
}
|
||||
|
||||
// SystemDataPaths determines system-wide possible paths for a data file.
|
||||
func SystemDataPaths(file string) []string {
|
||||
return defaultApp.SystemDataPaths(file)
|
||||
}
|
||||
|
||||
// SystemConfigPaths determines system-wide possible paths for a config file.
|
||||
func SystemConfigPaths(file string) []string {
|
||||
return defaultApp.SystemConfigPaths(file)
|
||||
}
|
23
vendor/github.com/casimir/xdg-go/xdg_darwin.go
generated
vendored
Normal file
23
vendor/github.com/casimir/xdg-go/xdg_darwin.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package xdg
|
||||
|
||||
import "os"
|
||||
|
||||
func DataHome() string {
|
||||
return os.Getenv("HOME") + "/Library"
|
||||
}
|
||||
|
||||
func ConfigHome() string {
|
||||
return os.Getenv("HOME") + "/Library/Preferences"
|
||||
}
|
||||
|
||||
func CacheHome() string {
|
||||
return os.Getenv("HOME") + "/Library/Caches"
|
||||
}
|
||||
|
||||
func DataDirs() []string {
|
||||
return []string{"/Library"}
|
||||
}
|
||||
|
||||
func ConfigDirs() []string {
|
||||
return []string{"/Library/Preferences", "/Library/Application Support"}
|
||||
}
|
25
vendor/github.com/casimir/xdg-go/xdg_linux.go
generated
vendored
Normal file
25
vendor/github.com/casimir/xdg-go/xdg_linux.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
package xdg
|
||||
|
||||
import "os"
|
||||
|
||||
func DataHome() string {
|
||||
return os.Getenv("HOME") + "/.local/share"
|
||||
}
|
||||
|
||||
func ConfigHome() string {
|
||||
return os.Getenv("HOME") + "/.config"
|
||||
}
|
||||
|
||||
func CacheHome() string {
|
||||
return os.Getenv("HOME") + "/.cache"
|
||||
}
|
||||
|
||||
func DataDirs() []string {
|
||||
// The specification gives a value with trailing slashes but only
|
||||
// for this value. Seems odd enough to take the liberty of removing them.
|
||||
return []string{"/usr/local/share", "/usr/share"}
|
||||
}
|
||||
|
||||
func ConfigDirs() []string {
|
||||
return []string{"/etc/xdg"}
|
||||
}
|
23
vendor/github.com/casimir/xdg-go/xdg_windows.go
generated
vendored
Normal file
23
vendor/github.com/casimir/xdg-go/xdg_windows.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package xdg
|
||||
|
||||
import "os"
|
||||
|
||||
func DataHome() string {
|
||||
return os.Getenv("APPDATA")
|
||||
}
|
||||
|
||||
func ConfigHome() string {
|
||||
return os.Getenv("APPDATA")
|
||||
}
|
||||
|
||||
func CacheHome() string {
|
||||
return os.Getenv("TEMP")
|
||||
}
|
||||
|
||||
func DataDirs() []string {
|
||||
return []string{os.Getenv("APPDATA"), os.Getenv("LOCALAPPDATA")}
|
||||
}
|
||||
|
||||
func ConfigDirs() []string {
|
||||
return []string{os.Getenv("APPDATA"), os.Getenv("LOCALAPPDATA")}
|
||||
}
|
Reference in New Issue
Block a user