@@ -16,10 +16,12 @@ import (
1616 "github.com/microsoft/go-sqlcmd/internal/cmdparser"
1717 "github.com/microsoft/go-sqlcmd/internal/cmdparser/dependency"
1818 "github.com/microsoft/go-sqlcmd/internal/config"
19+ "github.com/microsoft/go-sqlcmd/internal/io/file"
1920 "github.com/microsoft/go-sqlcmd/internal/output"
2021 "github.com/microsoft/go-sqlcmd/internal/output/verbosity"
2122 "github.com/microsoft/go-sqlcmd/pkg/sqlcmd"
2223 "github.com/spf13/cobra"
24+ "path"
2325
2426 "os"
2527
@@ -56,6 +58,25 @@ func main() {
5658// than env variables and env variables take higher precedence over config
5759// file info.
5860func 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+
5980 initializeCallback ()
6081 if config .CurrentContextName () != "" {
6182 server , username , password := config .GetCurrentContextInfo ()
0 commit comments