diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-09-28 15:46:09 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-09-28 15:46:09 +0000 |
commit | 3cf936123cda48a8856fb6cd534331f2dabe9e15 (patch) | |
tree | c4b4754790e619082ca935cef0bb489f3a6470b6 /go/cmd/gitlab-shell/main.go | |
parent | 1cc2993f357c4467e4d45c54c01d2307103efb3e (diff) | |
parent | f435c4644abc167cdfe6bfe3d320ff840f468c09 (diff) | |
download | gitlab-shell-3cf936123cda48a8856fb6cd534331f2dabe9e15.tar.gz |
Merge branch '74-go-go-go-go-go' into 'master'
Feature flag for go/ruby gitlab-shell implementations
Closes #74
See merge request gitlab-org/gitlab-shell!233
Diffstat (limited to 'go/cmd/gitlab-shell/main.go')
-rw-r--r-- | go/cmd/gitlab-shell/main.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go new file mode 100644 index 0000000..ae54151 --- /dev/null +++ b/go/cmd/gitlab-shell/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "syscall" + + "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" +) + +var ( + binDir string + rootDir string +) + +func init() { + binDir = filepath.Dir(os.Args[0]) + rootDir = filepath.Dir(binDir) +} + +func migrate(*config.Config) (int, bool) { + // TODO: Dispatch appropriate requests to Go handlers and return + // <exitstatus, true> depending on how they fare + return 0, false +} + +// rubyExec will never return. It either replaces the current process with a +// Ruby interpreter, or outputs an error and kills the process. +func execRuby() { + rubyCmd := filepath.Join(binDir, "gitlab-shell-ruby") + + execErr := syscall.Exec(rubyCmd, os.Args, os.Environ()) + if execErr != nil { + fmt.Fprintf(os.Stderr, "Failed to exec(%q): %v\n", rubyCmd, execErr) + os.Exit(1) + } +} + +func main() { + // Fall back to Ruby in case of problems reading the config, but issue a + // warning as this isn't something we can sustain indefinitely + config, err := config.NewFromDir(rootDir) + if err != nil { + fmt.Fprintln(os.Stderr, "Failed to read config, falling back to gitlab-shell-ruby") + execRuby() + } + + // Try to handle the command with the Go implementation + if exitCode, done := migrate(config); done { + os.Exit(exitCode) + } + + // Since a migration has not handled the command, fall back to Ruby to do so + execRuby() +} |