Fix error when automatic user detection fails
This commit is contained in:
@@ -3,6 +3,7 @@ package command
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"os/user"
|
||||
"strings"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
@@ -58,6 +59,14 @@ func ParseOptions(args []string) (Options, error) {
|
||||
opts.Prefix = os.Getenv("URL_PREFIX")
|
||||
}
|
||||
|
||||
if (opts.Host == "localhost" || opts.Host == "127.0.0.1") && opts.User == "" {
|
||||
if username := GetCurrentUser(); username != "" {
|
||||
opts.User = username
|
||||
} else {
|
||||
opts.Host = ""
|
||||
}
|
||||
}
|
||||
|
||||
if os.Getenv("SESSIONS") != "" {
|
||||
opts.Sessions = true
|
||||
}
|
||||
@@ -105,6 +114,7 @@ func ParseOptions(args []string) (Options, error) {
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// SetDefaultOptions parses and assigns the options
|
||||
func SetDefaultOptions() error {
|
||||
opts, err := ParseOptions([]string{})
|
||||
if err != nil {
|
||||
@@ -113,3 +123,12 @@ func SetDefaultOptions() error {
|
||||
Opts = opts
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCurrentUser returns a current user name
|
||||
func GetCurrentUser() string {
|
||||
u, _ := user.Current()
|
||||
if u != nil {
|
||||
return u.Username
|
||||
}
|
||||
return os.Getenv("USER")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user