summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--internal/cli/root.go10
-rw-r--r--internal/cli/root_test.go30
4 files changed, 39 insertions, 5 deletions
diff --git a/go.mod b/go.mod
index 1bbb6a24..8e7adaff 100644
--- a/go.mod
+++ b/go.mod
@@ -55,6 +55,8 @@ require (
github.com/vbauerster/mpb/v5 v5.4.0
)
+replace github.com/roadrunner-server/config/v2 => ../plugins/config
+
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
diff --git a/go.sum b/go.sum
index 0e5d061f..88e8459e 100644
--- a/go.sum
+++ b/go.sum
@@ -436,8 +436,6 @@ github.com/roadrunner-server/broadcast/v2 v2.11.2 h1:rYq0umlXrbIwleWS41W+c96SakP
github.com/roadrunner-server/broadcast/v2 v2.11.2/go.mod h1:6XAE7LRQToEB/zv0iEbBI2APPbjmIHd4kN6AwJLdW9A=
github.com/roadrunner-server/cache/v2 v2.12.2 h1:OePy9morZOgwjymRvZZl/g5gO/EsIRohz95jIcbyIjk=
github.com/roadrunner-server/cache/v2 v2.12.2/go.mod h1:h0HH+9MiIVLwMvSMmp3S20e+8HHsbzynTXbVREKh/r4=
-github.com/roadrunner-server/config/v2 v2.13.2 h1:Ja5qL80hkuJSIzjJMiYMnKH/thIVyS/N4ZiEQwCXW+U=
-github.com/roadrunner-server/config/v2 v2.13.2/go.mod h1:AAnBVCYJdfT3Wo6rr8jxkOH3AAvPey+47eFFc7zLYOc=
github.com/roadrunner-server/endure v1.2.3 h1:Smm+pHDERzeqXsLO602oe5iy0q+w94jAH3UT1pqgZiY=
github.com/roadrunner-server/endure v1.2.3/go.mod h1:Yahi4Uoabla2o+0N+pbjWwIJnAigYWppGwbLU3D6cLc=
github.com/roadrunner-server/errors v1.1.2 h1:+LPw9Akgg+8LAGM4wASMWLAoBIbyP+mhNfR+FBS2Slw=
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
+ }
}
}
diff --git a/internal/cli/root_test.go b/internal/cli/root_test.go
index 602b9d3b..f77acec3 100644
--- a/internal/cli/root_test.go
+++ b/internal/cli/root_test.go
@@ -135,3 +135,33 @@ func TestCommandNoEnvFileNoError(t *testing.T) {
_ = os.RemoveAll(path.Join(tmp, ".rr.yaml"))
})
}
+
+func TestCommandWorkingDir(t *testing.T) {
+ tmp := os.TempDir()
+
+ cmd := cli.NewCommand("serve")
+ cmd.SetArgs([]string{"-w", tmp})
+
+ var executed bool
+
+ var wd string
+
+ f2, err := os.Create(path.Join(tmp, ".rr.yaml"))
+ require.NoError(t, err)
+
+ if cmd.Run == nil { // override "Run" property for test (if it was not set)
+ cmd.Run = func(cmd *cobra.Command, args []string) {
+ executed = true
+ wd, _ = os.Getwd()
+ }
+ }
+
+ assert.NoError(t, cmd.Execute())
+ assert.True(t, executed)
+ assert.Equal(t, "/tmp", wd)
+
+ t.Cleanup(func() {
+ _ = f2.Close()
+ _ = os.RemoveAll(path.Join(tmp, ".rr.yaml"))
+ })
+}