Skip to content

Commit

Permalink
Can't rely on os/user for x-compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
andreimarcu committed Oct 27, 2015
1 parent b4f92eb commit 2b984a2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 61 deletions.
18 changes: 12 additions & 6 deletions configdir_darwin.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package main

import (
"os/user"
"os"
"path/filepath"
)

func configDir() string {
usr, err := user.Current()
if err != nil {
return ""
func getHomeDir() (homeDir string) {
homeDir = os.Getenv("HOME")
if homeDir == "" {
homeDir = getInput("Path to home directory", false)
}

return filepath.Join(usr.HomeDir, ".config")
return
}

func getConfigDir() (configDir string) {
configDir = filepath.Join(getHomeDir(), ".config")

return
}
20 changes: 10 additions & 10 deletions configdir_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package main

import (
"os"
"os/user"
"path/filepath"
)

func configDir() string {
confDir := os.Getenv("XDG_CONFIG_HOME")
if confDir != "" {
return confDir
func getHomeDir() (homeDir string) {
homeDir = os.Getenv("HOME")
if homeDir == "" {
homeDir = getInput("Path to home directory", false)
}

usr, err := user.Current()
if err != nil {
return ""
}
return
}

func getConfigDir() (configDir string) {
configDir = filepath.Join(getHomeDir(), ".config")

return filepath.Join(usr.HomeDir, ".config")
return
}
20 changes: 10 additions & 10 deletions configdir_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package main

import (
"os"
"os/user"
"path/filepath"
)

func configDir() string {
confDir := os.Getenv("XDG_CONFIG_HOME")
if confDir != "" {
return confDir
func getHomeDir() (homeDir string) {
homeDir = os.Getenv("HOME")
if homeDir == "" {
homeDir = getInput("Path to home directory", false)
}

usr, err := user.Current()
if err != nil {
return ""
}
return
}

func getConfigDir() (configDir string) {
configDir = filepath.Join(getHomeDir(), ".config")

return filepath.Join(usr.HomeDir, ".config")
return
}
20 changes: 10 additions & 10 deletions configdir_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package main

import (
"os"
"os/user"
"path/filepath"
)

func configDir() string {
confDir := os.Getenv("XDG_CONFIG_HOME")
if confDir != "" {
return confDir
func getHomeDir() (homeDir string) {
homeDir = os.Getenv("HOME")
if homeDir == "" {
homeDir = getInput("Path to home directory", false)
}

usr, err := user.Current()
if err != nil {
return ""
}
return
}

func getConfigDir() (configDir string) {
configDir = filepath.Join(getHomeDir(), ".config")

return filepath.Join(usr.HomeDir, ".config")
return
}
20 changes: 14 additions & 6 deletions configdir_windows.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package main

import (
"os/user"
"os"
)

func configDir() string {
usr, err := user.Current()
if err != nil {
return ""
func getHomeDir() (homeDir string) {
homeDir = os.Getenv("HOMEPATH")
if homeDir == "" {
homeDir = getInput("Path to home directory", false)
}

return usr.HomeDir
return
}

func getConfigDir() (configDir string) {
configDir = os.Getenv("APPDATA")
if configDir == "" {
configDir = getInput("Path to config directory", false)
}
return
}
29 changes: 10 additions & 19 deletions linx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"net/url"
"os"
"os/user"
"path"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -190,7 +189,7 @@ func writeKeys() {
}

func parseConfig() {
cfgFilePath := filepath.Join(configDir(), "linx-client.conf")
cfgFilePath := filepath.Join(getConfigDir(), "linx-client.conf")
cfg, err := config.LoadOrCreate(cfgFilePath)
checkErr(err)

Expand All @@ -202,30 +201,29 @@ func parseConfig() {
fmt.Println("Configuring linx-client")
fmt.Println()
for Config.siteurl == "" {
fmt.Print("Site url (ex: https://linx.example.com/): ")
fmt.Scanf("%s", &Config.siteurl)
Config.siteurl = getInput("Site url (ex: https://linx.example.com/)", false)

if lastChar := Config.siteurl[len(Config.siteurl)-1:]; lastChar != "/" {
Config.siteurl = Config.siteurl + "/"
}
}
cfg.SetValue("siteurl", Config.siteurl)

for Config.logfile == "" {
fmt.Print("Logfile path (ex: ~/.linxlog): ")
fmt.Scanf("%s", &Config.logfile)
Config.logfile = getInput("Logfile path (ex: ~/.linxlog)", false)

usr, err := user.Current()
checkErr(err)
homeDir := getHomeDir()
if lastChar := homeDir[len(homeDir)-1:]; lastChar != "/" {
homeDir = homeDir + "/"
}

homedir := usr.HomeDir + "/"
Config.logfile = strings.Replace(Config.logfile, "~/", homedir, 1)
Config.logfile = strings.Replace(Config.logfile, "~/", homeDir, 1)

}
cfg.SetValue("logfile", Config.logfile)

if Config.apikey == "" {
fmt.Print("API key (leave blank if instance is public): ")
fmt.Scanf("%s", &Config.apikey)
Config.apikey = getInput("API key (leave blank if instance is public)", true)
}
cfg.SetValue("apikey", Config.apikey)

Expand All @@ -234,10 +232,3 @@ func parseConfig() {
fmt.Printf("Configuration written at %s\n", cfgFilePath)
}
}

func checkErr(err error) {
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}

0 comments on commit 2b984a2

Please sign in to comment.