Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-15 15:55:58 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-07-20 07:32:18 +0300
commitfb1cd5ff1274d10d9bebb2a714e2dcc19375f5aa (patch)
tree9d825fc6a732fc1bddd060d8b0ada5b03f9b613d /internal/command
parent52f009b5d14ee7dac418498c1b389cb11d43cf80 (diff)
command: Add `WithDir()` option
Callers of the command package that wanted to run the command in a specific directory had to manually set the directory of the `exec.Cmd` they passed into the command package. This is a weird calling convention as ideally, the command package should handle the complete setup for the caller. Add a new option `WithDir()` to handle this usecase inside of the command package and convert callers to use it.
Diffstat (limited to 'internal/command')
-rw-r--r--internal/command/command.go2
-rw-r--r--internal/command/option.go8
2 files changed, 10 insertions, 0 deletions
diff --git a/internal/command/command.go b/internal/command/command.go
index f7c1936c6..834360a75 100644
--- a/internal/command/command.go
+++ b/internal/command/command.go
@@ -204,6 +204,8 @@ func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) {
cmdGitVersion: cfg.gitVersion,
}
+ cmd.Dir = cfg.dir
+
// Export allowed environment variables as set in the Gitaly process.
cmd.Env = AllowedEnvironment(os.Environ())
// Append environment variables explicitly requested by the caller.
diff --git a/internal/command/option.go b/internal/command/option.go
index d5ec59635..cca8e62f1 100644
--- a/internal/command/option.go
+++ b/internal/command/option.go
@@ -10,6 +10,7 @@ type config struct {
stdin io.Reader
stdout io.Writer
stderr io.Writer
+ dir string
environment []string
finalizer func(*Command)
@@ -56,6 +57,13 @@ func WithStderr(stderr io.Writer) Option {
}
}
+// WithDir will set up the command to be ran in the specific directory.
+func WithDir(dir string) Option {
+ return func(cfg *config) {
+ cfg.dir = dir
+ }
+}
+
// WithEnvironment sets up environment variables that shall be set for the command.
func WithEnvironment(environment []string) Option {
return func(cfg *config) {