diff options
author | Valery Piashchynski <[email protected]> | 2022-04-28 11:52:16 +0200 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2022-04-28 11:52:16 +0200 |
commit | 92b3e31e54dce17421abceb16994f5a1c7a4f521 (patch) | |
tree | 999c2e9c18885064a3c69a2a44182e6a79b45678 /internal/cli/root.go | |
parent | f8119b8a366b1788fd71b321a807adf3ba9521a4 (diff) |
fix chdir routine
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal/cli/root.go')
-rw-r--r-- | internal/cli/root.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/cli/root.go b/internal/cli/root.go index 7e22124a..0df74be0 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -46,18 +46,22 @@ func NewCommand(cmdName string) *cobra.Command { //nolint:funlen return errors.Str("no configuration file provided") } + // if user set the wd, change the current wd if workDir != "" { if err := os.Chdir(workDir); err != nil { return err } } + // try to get the absolute path to the configuration if absPath, err := filepath.Abs(*cfgFile); err == nil { *cfgFile = absPath // switch config path to the absolute - // force working absPath related to config file - if err = os.Chdir(filepath.Dir(absPath)); err != nil { - return err + // if workDir is empty - force working absPath related to config file + if workDir == "" { + if err = os.Chdir(filepath.Dir(absPath)); err != nil { + return err + } } } |