@@ -16,10 +16,12 @@ import (
16
16
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
17
17
"github.com/microsoft/go-sqlcmd/internal/cmdparser/dependency"
18
18
"github.com/microsoft/go-sqlcmd/internal/config"
19
+ "github.com/microsoft/go-sqlcmd/internal/io/file"
19
20
"github.com/microsoft/go-sqlcmd/internal/output"
20
21
"github.com/microsoft/go-sqlcmd/internal/output/verbosity"
21
22
"github.com/microsoft/go-sqlcmd/pkg/sqlcmd"
22
23
"github.com/spf13/cobra"
24
+ "path"
23
25
24
26
"os"
25
27
@@ -56,6 +58,25 @@ func main() {
56
58
// than env variables and env variables take higher precedence over config
57
59
// file info.
58
60
func initializeEnvVars () {
61
+ home , err := os .UserHomeDir ()
62
+
63
+ // Special case, some shells don't have any home dir env var set, see:
64
+ // https://github.com/microsoft/go-sqlcmd/issues/279
65
+ // in this case, we early exit here and don't initialize anything, there is nothing
66
+ // else we can do
67
+ if err != nil {
68
+ return
69
+ }
70
+
71
+ // The only place we can check for the existence of the sqlconfig file is in the
72
+ // default location, because this code path is only used for the legacy kong CLI,
73
+ // if the sqlconfig file doesn't exist at the default location we just return so
74
+ // because the initializeCallback() function below will create the sqlconfig file,
75
+ // which legacy sqlcmd users might not want.
76
+ if ! file .Exists (path .Join (home , ".sqlcmd" , "sqlconfig" )) {
77
+ return
78
+ }
79
+
59
80
initializeCallback ()
60
81
if config .CurrentContextName () != "" {
61
82
server , username , password := config .GetCurrentContextInfo ()
0 commit comments