Skip to content

Commit d660799

Browse files
committed
Recoded user.Current for cross-compiling
1 parent c838faa commit d660799

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cli.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ package main
44
import (
55
"bytes"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io/ioutil"
910
"os"
10-
"os/user"
11+
"path/filepath"
1112
"strings"
1213
"text/template"
1314

@@ -265,7 +266,7 @@ func main() {
265266
var cfg_err error
266267
config, cfg_err = getConfig()
267268
if cfg_err != nil && !os.IsNotExist(cfg_err) {
268-
log.Fatalf("unable to open .scwrc config file: %s", cfg_err)
269+
log.Fatalf("Unable to open .scwrc config file: %v", cfg_err)
269270
}
270271

271272
if config != nil {
@@ -304,7 +305,7 @@ func main() {
304305
}
305306
if cmd.Name() != "login" {
306307
if cfg_err != nil {
307-
log.Fatalf("unable to open .scwrc config file: %s", cfg_err)
308+
log.Fatalf("Unable to open .scwrc config file: %v", cfg_err)
308309
}
309310
api, err := getScalewayAPI()
310311
if err != nil {
@@ -342,11 +343,15 @@ type Config struct {
342343

343344
// GetConfigFilePath returns the path to the Scaleway CLI config file
344345
func GetConfigFilePath() (string, error) {
345-
u, err := user.Current()
346-
if err != nil {
347-
return "", err
346+
homeDir := os.Getenv("HOME") // *nix
347+
if homeDir == "" { // Windows
348+
homeDir = os.Getenv("USERPROFILE")
348349
}
349-
return fmt.Sprintf("%s/.scwrc", u.HomeDir), nil
350+
if homeDir == "" {
351+
return "", errors.New("User home directory not found.")
352+
}
353+
354+
return filepath.Join(homeDir, ".scwrc"), nil
350355
}
351356

352357
// getConfig returns the Scaleway CLI config file for the current user

0 commit comments

Comments
 (0)