summaryrefslogtreecommitdiff
path: root/go/internal/command/fallback/fallback.go
blob: cec94d5acfe693674bc9cb2ddea01f5403ad107d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package fallback

import (
	"fmt"
	"os"
	"path/filepath"
	"syscall"

	"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
)

type CommandArgs interface {
	Executable() commandargs.Executable
	Arguments() []string
}

type Command struct {
	RootDir string
	Args    CommandArgs
}

var (
	// execFunc is overridden in tests
	execFunc = syscall.Exec
)

func (c *Command) Execute() error {
	rubyCmd := filepath.Join(c.RootDir, "bin", c.fallbackProgram())

	// Ensure rubyArgs[0] is the full path to gitlab-shell-ruby
	rubyArgs := append([]string{rubyCmd}, c.Args.Arguments()...)

	return execFunc(rubyCmd, rubyArgs, os.Environ())
}

func (c *Command) fallbackProgram() string {
	return fmt.Sprintf("%s-ruby", c.Args.Executable())
}