summaryrefslogtreecommitdiff
path: root/vendor/github.com/Wessie/appdirs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/Wessie/appdirs')
-rw-r--r--vendor/github.com/Wessie/appdirs/LICENSE18
-rw-r--r--vendor/github.com/Wessie/appdirs/appdirs.go80
-rw-r--r--vendor/github.com/Wessie/appdirs/appdirs_darwin.go63
-rw-r--r--vendor/github.com/Wessie/appdirs/appdirs_unix.go102
-rw-r--r--vendor/github.com/Wessie/appdirs/appdirs_windows.go171
-rw-r--r--vendor/github.com/Wessie/appdirs/doc.go108
6 files changed, 542 insertions, 0 deletions
diff --git a/vendor/github.com/Wessie/appdirs/LICENSE b/vendor/github.com/Wessie/appdirs/LICENSE
new file mode 100644
index 0000000..6b2f3ee
--- /dev/null
+++ b/vendor/github.com/Wessie/appdirs/LICENSE
@@ -0,0 +1,18 @@
+Copyright (c) 2013 Wesley Bitter
+
+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.
diff --git a/vendor/github.com/Wessie/appdirs/appdirs.go b/vendor/github.com/Wessie/appdirs/appdirs.go
new file mode 100644
index 0000000..1577cb9
--- /dev/null
+++ b/vendor/github.com/Wessie/appdirs/appdirs.go
@@ -0,0 +1,80 @@
+// A port of the excellent python module `appdirs`.
+// See https://github.com/ActiveState/appdirs for the python version.
+package appdirs
+
+import (
+ "os/user"
+ "strings"
+)
+
+// App is a helper type to create easy access across your program to the appdirs
+// functions.
+//
+// The *App type has 6 methods that map to the 6 functions exported by `appdirs`.
+// All methods take no arguments, and supply the function it wraps with arguments
+// pre-set in the struct on creation.
+type App struct {
+ Name string
+ Author string
+ Version string
+ Roaming bool
+ Opinion bool
+}
+
+// New returns a new App helper that has various methods for receiving
+// relevant directories for your application.
+//
+// The following defaults are used for the two fields not settable by New:
+// Roaming: false, Opinion: true
+//
+// If you want to set these, create your own App struct by the usual means.
+func New(name, author, version string) *App {
+ return &App{
+ Name: name,
+ Author: author,
+ Version: version,
+ Roaming: false,
+ Opinion: true,
+ }
+}
+
+// UserData returns the full path to the user-specific data directory
+func (app *App) UserData() string {
+ return UserDataDir(app.Name, app.Author, app.Version, app.Roaming)
+}
+
+// SiteData returns the full path to the user-shared data directory
+func (app *App) SiteData() string {
+ return SiteDataDir(app.Name, app.Author, app.Version)
+}
+
+// SiteConfig returns the full path to the user-shared configuration directory
+func (app *App) SiteConfig() string {
+ return SiteConfigDir(app.Name, app.Author, app.Version)
+}
+
+// UserConfig returns the full path to the user-specific configuration directory
+func (app *App) UserConfig() string {
+ return UserConfigDir(app.Name, app.Author, app.Version, app.Roaming)
+}
+
+// UserCache returns the full path to the user-specific cache directory
+func (app *App) UserCache() string {
+ return UserCacheDir(app.Name, app.Author, app.Version, app.Opinion)
+}
+
+// UserLog returns the full path to the user-specific log directory
+func (app *App) UserLog() string {
+ return UserLogDir(app.Name, app.Author, app.Version, app.Opinion)
+}
+
+// ExpandUser is a helper function that expands the first '~' it finds in the
+// passed path with the home directory of the current user.
+//
+// Note: This only works on environments similar to bash.
+func ExpandUser(path string) string {
+ if u, err := user.Current(); err == nil {
+ return strings.Replace(path, "~", u.HomeDir, -1)
+ }
+ return path
+}
diff --git a/vendor/github.com/Wessie/appdirs/appdirs_darwin.go b/vendor/github.com/Wessie/appdirs/appdirs_darwin.go
new file mode 100644
index 0000000..29b6ae8
--- /dev/null
+++ b/vendor/github.com/Wessie/appdirs/appdirs_darwin.go
@@ -0,0 +1,63 @@
+package appdirs
+
+import (
+ "path/filepath"
+)
+
+func userDataDir(name, author, version string, roaming bool) (path string) {
+ path = ExpandUser("~/Library/Application Support")
+
+ if name != "" {
+ path = filepath.Join(path, name)
+ }
+
+ if name != "" && version != "" {
+ path = filepath.Join(path, version)
+ }
+ return path
+}
+
+func siteDataDir(name, author, version string) (path string) {
+ path = ExpandUser("/Library/Application Support")
+
+ if name != "" {
+ path = filepath.Join(path, name)
+ }
+
+ if name != "" && version != "" {
+ path = filepath.Join(path, version)
+ }
+ return path
+}
+
+func userConfigDir(name, author, version string, roaming bool) (path string) {
+ return UserDataDir(name, author, version, roaming)
+}
+
+func siteConfigDir(name, author, version string) (path string) {
+ return SiteDataDir(name, author, version)
+}
+
+func userCacheDir(name, author, version string, opinion bool) (path string) {
+ path = ExpandUser("~/Library/Caches")
+
+ if name != "" {
+ path = filepath.Join(path, name)
+ }
+
+ if name != "" && version != "" {
+ path = filepath.Join(path, version)
+ }
+ return path
+}
+
+func userLogDir(name, author, version string, opinion bool) (path string) {
+ path = ExpandUser("~/Library/Logs")
+
+ path = filepath.Join(path, name)
+
+ if name != "" && version != "" {
+ path = filepath.Join(path, version)
+ }
+ return path
+}
diff --git a/vendor/github.com/Wessie/appdirs/appdirs_unix.go b/vendor/github.com/Wessie/appdirs/appdirs_unix.go
new file mode 100644
index 0000000..99c9917
--- /dev/null
+++ b/vendor/github.com/Wessie/appdirs/appdirs_unix.go
@@ -0,0 +1,102 @@
+// +build linux freebsd netbsd openbsd
+
+package appdirs
+
+import (
+ "os"
+ "path/filepath"
+)
+
+func userDataDir(name, author, version string, roaming bool) (path string) {
+ if path = os.Getenv("XDG_DATA_HOME"); path == "" {
+ path = ExpandUser("~/.local/share")
+ }
+
+ if name != "" {
+ path = filepath.Join(path, name, version)
+ }
+
+ return path
+}
+
+func SiteDataDirs(name, author, version string) (paths []string) {
+ var path string
+
+ if path = os.Getenv("XDG_DATA_DIRS"); path == "" {
+ paths = []string{"/usr/local/share", "/usr/share"}
+ } else {
+ paths = filepath.SplitList(path)
+ }
+
+ for i, path := range paths {
+ path = ExpandUser(path)
+
+ if name != "" {
+ path = filepath.Join(path, name, version)
+ }
+
+ paths[i] = path
+ }
+
+ return paths
+}
+
+func siteDataDir(name, author, version string) (path string) {
+ return SiteDataDirs(name, author, version)[0]
+}
+
+func userConfigDir(name, author, version string, roaming bool) (path string) {
+ if path = os.Getenv("XDG_CONFIG_HOME"); path == "" {
+ path = ExpandUser("~/.config")
+ }
+
+ if name != "" {
+ path = filepath.Join(path, name, version)
+ }
+
+ return path
+}
+
+func SiteConfigDirs(name, author, version string) (paths []string) {
+ var path string
+
+ if path = os.Getenv("XDG_CONFIG_DIRS"); path == "" {
+ paths = []string{"/etc/xdg"}
+ } else {
+ paths = filepath.SplitList(path)
+ }
+
+ for i, path := range paths {
+ path = ExpandUser(path)
+
+ if name != "" {
+ path = filepath.Join(path, name, version)
+ }
+
+ paths[i] = path
+ }
+
+ return paths
+}
+
+func siteConfigDir(name, author, version string) (path string) {
+ return SiteConfigDirs(name, author, version)[0]
+}
+
+func userCacheDir(name, author, version string, opinion bool) (path string) {
+ if path = os.Getenv("XDG_CACHE_HOME"); path == "" {
+ path = ExpandUser("~/.cache")
+ }
+
+ if name != "" {
+ path = filepath.Join(path, name, version)
+ }
+
+ return path
+}
+
+func userLogDir(name, author, version string, opinion bool) (path string) {
+ path = UserCacheDir(name, author, version, opinion)
+
+ return filepath.Join(path, "log")
+}
diff --git a/vendor/github.com/Wessie/appdirs/appdirs_windows.go b/vendor/github.com/Wessie/appdirs/appdirs_windows.go
new file mode 100644
index 0000000..ca897af
--- /dev/null
+++ b/vendor/github.com/Wessie/appdirs/appdirs_windows.go
@@ -0,0 +1,171 @@
+package appdirs
+
+import (
+ "path/filepath"
+ "syscall"
+ "unsafe"
+)
+
+var (
+ shell32, _ = syscall.LoadLibrary("shell32.dll")
+ getKnownFolderPath, _ = syscall.GetProcAddress(shell32, "SHGetKnownFolderPath")
+
+ ole32, _ = syscall.LoadLibrary("Ole32.dll")
+ coTaskMemFree, _ = syscall.GetProcAddress(ole32, "CoTaskMemFree")
+)
+
+// These are KNOWNFOLDERID constants that are passed to GetKnownFolderPath
+var (
+ rfidLocalAppData = syscall.GUID{
+ 0xf1b32785,
+ 0x6fba,
+ 0x4fcf,
+ [8]byte{0x9d, 0x55, 0x7b, 0x8e, 0x7f, 0x15, 0x70, 0x91},
+ }
+ rfidRoamingAppData = syscall.GUID{
+ 0x3eb685db,
+ 0x65f9,
+ 0x4cf6,
+ [8]byte{0xa0, 0x3a, 0xe3, 0xef, 0x65, 0x72, 0x9f, 0x3d},
+ }
+ rfidProgramData = syscall.GUID{
+ 0x62ab5d82,
+ 0xfdc1,
+ 0x4dc3,
+ [8]byte{0xa9, 0xdd, 0x07, 0x0d, 0x1d, 0x49, 0x5d, 0x97},
+ }
+)
+
+func userDataDir(name, author, version string, roaming bool) (path string) {
+ if author == "" {
+ author = name
+ }
+
+ var rfid syscall.GUID
+ if roaming {
+ rfid = rfidRoamingAppData
+ } else {
+ rfid = rfidLocalAppData
+ }
+
+ path, err := getFolderPath(rfid)
+
+ if err != nil {
+ return ""
+ }
+
+ if path, err = filepath.Abs(path); err != nil {
+ return ""
+ }
+
+ if name != "" {
+ path = filepath.Join(path, author, name)
+ }
+
+ if name != "" && version != "" {
+ path = filepath.Join(path, version)
+ }
+
+ return path
+}
+
+func siteDataDir(name, author, version string) (path string) {
+ path, err := getFolderPath(rfidProgramData)
+
+ if err != nil {
+ return ""
+ }
+
+ if path, err = filepath.Abs(path); err != nil {
+ return ""
+ }
+
+ if author == "" {
+ author = name
+ }
+
+ if name != "" {
+ path = filepath.Join(path, author, name)
+ }
+
+ if name != "" && version != "" {
+ path = filepath.Join(path, version)
+ }
+
+ return path
+}
+
+func userConfigDir(name, author, version string, roaming bool) string {
+ return UserDataDir(name, author, version, roaming)
+}
+
+func siteConfigDir(name, author, version string) (path string) {
+ return SiteDataDir(name, author, version)
+}
+
+func userCacheDir(name, author, version string, opinion bool) (path string) {
+ if author == "" {
+ author = name
+ }
+
+ path, err := getFolderPath(rfidLocalAppData)
+
+ if err != nil {
+ return ""
+ }
+
+ if path, err = filepath.Abs(path); err != nil {
+ return ""
+ }
+
+ if name != "" {
+ path = filepath.Join(path, author, name)
+ if opinion {
+ path = filepath.Join(path, "Cache")
+ }
+ }
+
+ if name != "" && version != "" {
+ path = filepath.Join(path, version)
+ }
+
+ return path
+}
+
+func userLogDir(name, author, version string, opinion bool) (path string) {
+ path = UserDataDir(name, author, version, false)
+
+ if opinion {
+ path = filepath.Join(path, "Logs")
+ }
+
+ return path
+}
+
+func getFolderPath(rfid syscall.GUID) (string, error) {
+ var res uintptr
+
+ ret, _, callErr := syscall.Syscall6(
+ uintptr(getKnownFolderPath),
+ 4,
+ uintptr(unsafe.Pointer(&rfid)),
+ 0,
+ 0,
+ uintptr(unsafe.Pointer(&res)),
+ 0,
+ 0,
+ )
+
+ if callErr != 0 && ret != 0 {
+ return "", callErr
+ }
+
+ defer syscall.Syscall(uintptr(coTaskMemFree), 1, res, 0, 0)
+ return ucs2PtrToString(res), nil
+}
+
+func ucs2PtrToString(p uintptr) string {
+ ptr := (*[4096]uint16)(unsafe.Pointer(p))
+
+ return syscall.UTF16ToString((*ptr)[:])
+}
diff --git a/vendor/github.com/Wessie/appdirs/doc.go b/vendor/github.com/Wessie/appdirs/doc.go
new file mode 100644
index 0000000..4311627
--- /dev/null
+++ b/vendor/github.com/Wessie/appdirs/doc.go
@@ -0,0 +1,108 @@
+// appdirs project doc.go
+
+/*
+This is a port of a python module used for finding what directory you 'should'
+be using for saving your application data such as configuration, cache files or
+other files.
+
+The location of these directories is often hard to get right. The original python
+module set out to change this into a simple API that returns you the exact
+directory you need. This is a port of it to Go.
+
+Depending on platform, this package exports you at the least 6 functions that
+return various system directories. And one helper struct type that combines the
+functions into methods for less arguments in your code.
+
+Each function defined accepts a number of arguments, each argument is optional
+and can be left to the types default value if omitted. Often the function will
+ignore arguments if the name given is empty.
+
+Passing in all default values into any of the functions will return you the base
+directory without any of the arguments appended to it.
+*/
+package appdirs
+
+// UserDataDir returns the full path to the user-specific data directory.
+//
+// This function uses XDG_DATA_HOME as defined by the XDG spec on *nix like systems.
+//
+// Examples of return values:
+// Mac OS X: ~/Library/Application Support/<AppName>
+// Unix: ~/.local/share/<AppName> # or in $XDG_DATA_HOME, if defined
+// Win XP (not roaming): C:\Documents and Settings\<username>\Application Data\<AppAuthor>\<AppName>
+// Win XP (roaming): C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>
+// Win 7 (not roaming): C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>
+// Win 7 (roaming): C:\Users\<username>\AppData\Roaming\<AppAuthor>\<AppName>
+func UserDataDir(name, author, version string, roaming bool) string {
+ return userDataDir(name, author, version, roaming)
+}
+
+// SiteDataDir returns the full path to the user-shared data directory.
+//
+// This function uses XDG_DATA_DIRS[0] as by the XDG spec on *nix like systems.
+//
+// Examples of return values:
+// Mac OS X: /Library/Application Support/<AppName>
+// Unix: /usr/local/share/<AppName> or /usr/share/<AppName>
+// Win XP: C:\Documents and Settings\All Users\Application Data\<AppAuthor>\<AppName>
+// Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
+// Win 7: C:\ProgramData\<AppAuthor>\<AppName> # Hidden, but writeable on Win 7.
+//
+// WARNING: Do not use this on Windows Vista, See the note above.
+func SiteDataDir(name, author, version string) string {
+ return siteDataDir(name, author, version)
+}
+
+// UserConfigDir returns the full path to the user-specific configuration directory
+//
+// This function uses XDG_CONFIG_HOME as by the XDG spec on *nix like systems.
+//
+// Examples of return values:
+// Mac OS X: same as UserDataDir
+// Unix: ~/.config/<AppName> # or in $XDG_CONFIG_HOME, if defined
+// Win *: same as UserDataDir
+func UserConfigDir(name, author, version string, roaming bool) string {
+ return userConfigDir(name, author, version, roaming)
+}
+
+// SiteConfigDir returns the full path to the user-shared data directory.
+//
+// This function uses XDG_CONFIG_DIRS[0] as by the XDG spec on *nix like systems.
+//
+// Examples of return values:
+// Mac OS X: same as SiteDataDir
+// Unix: /etc/xdg/<AppName> or $XDG_CONFIG_DIRS[i]/<AppName> for each value in $XDG_CONFIG_DIRS
+// Win *: same as SiteDataDir
+// Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.)
+//
+// WARNING: Do not use this on Windows Vista, see the note above.
+func SiteConfigDir(name, author, version string) string {
+ return siteConfigDir(name, author, version)
+}
+
+// UserCacheDir returns the full path to the user-specific cache directory.
+//
+// The opinion argument will append 'Cache' to the base directory if set to true.
+//
+// Examples of return values:
+// Mac OS X: ~/Library/Caches/<AppName>
+// Unix: ~/.cache/<AppName> (XDG default)
+// Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Cache
+// Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Cache
+func UserCacheDir(name, author, version string, opinion bool) string {
+ return userCacheDir(name, author, version, opinion)
+}
+
+// UserLogDir returns the full path to the user-specific log directory.
+//
+// The opinion argument will append either 'Logs' (windows) or 'log' (unix) to
+// the base directory when set to true.
+//
+// Examples of return values:
+// Mac OS X: ~/Library/Logs/<AppName>
+// Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if defined
+// Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs
+// Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Logs
+func UserLogDir(name, author, version string, opinion bool) string {
+ return userLogDir(name, author, version, opinion)
+}