mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Now expects config.yml to be in ~/.wtf/config.yml
This commit is contained in:
parent
c3f1d7ee36
commit
d41f5f5f99
49
homedir/homedir.go
Normal file
49
homedir/homedir.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
// Package homedir helps with detecting and expanding the user's home directory
|
||||||
|
|
||||||
|
// Copied verbatim from https://github.com/Atrox/homedir
|
||||||
|
|
||||||
|
package homedir
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Dir returns the home directory for the executing user.
|
||||||
|
// An error is returned if a home directory cannot be detected.
|
||||||
|
func Dir() (string, error) {
|
||||||
|
currentUser, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if currentUser.HomeDir == "" {
|
||||||
|
return "", errors.New("cannot find user-specific home dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentUser.HomeDir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expand expands the path to include the home directory if the path
|
||||||
|
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
|
||||||
|
// returned as-is.
|
||||||
|
func Expand(path string) (string, error) {
|
||||||
|
if len(path) == 0 {
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if path[0] != '~' {
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(path) > 1 && path[1] != '/' && path[1] != '\\' {
|
||||||
|
return "", errors.New("cannot expand user-specific home dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
dir, err := Dir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return filepath.Join(dir, path[1:]), nil
|
||||||
|
}
|
5
wtf.go
5
wtf.go
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/senorprogrammer/wtf/bamboohr"
|
"github.com/senorprogrammer/wtf/bamboohr"
|
||||||
"github.com/senorprogrammer/wtf/gcal"
|
"github.com/senorprogrammer/wtf/gcal"
|
||||||
"github.com/senorprogrammer/wtf/git"
|
"github.com/senorprogrammer/wtf/git"
|
||||||
|
"github.com/senorprogrammer/wtf/homedir"
|
||||||
"github.com/senorprogrammer/wtf/jira"
|
"github.com/senorprogrammer/wtf/jira"
|
||||||
"github.com/senorprogrammer/wtf/opsgenie"
|
"github.com/senorprogrammer/wtf/opsgenie"
|
||||||
"github.com/senorprogrammer/wtf/security"
|
"github.com/senorprogrammer/wtf/security"
|
||||||
@ -18,7 +19,9 @@ import (
|
|||||||
var Config = loadConfig()
|
var Config = loadConfig()
|
||||||
|
|
||||||
func loadConfig() *config.Config {
|
func loadConfig() *config.Config {
|
||||||
cfg, err := config.ParseYamlFile("./config.yml")
|
configPath, _ := homedir.Expand("~/.wtf/config.yml")
|
||||||
|
|
||||||
|
cfg, err := config.ParseYamlFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user