diff options
author | Nick Thomas <nick@gitlab.com> | 2019-01-15 23:36:21 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-01-15 23:36:21 +0000 |
commit | 1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258 (patch) | |
tree | c246e5b43a1e7b5744e10e75d6ed125629f45936 /go/cmd/gitlab-shell/main.go | |
parent | 6c5b195353a632095d7f672d28b9985fd879b077 (diff) | |
parent | d762f4ec9ea35cb00309b41ad60055cd3c5709ba (diff) | |
download | gitlab-shell-1fcb56f42cdb2b6f562d8875abc4e33f7ef3e258.tar.gz |
Merge branch 'bvl-feature-flag-commands' into 'master'
Parse commands to enable feature flags
See merge request gitlab-org/gitlab-shell!270
Diffstat (limited to 'go/cmd/gitlab-shell/main.go')
-rw-r--r-- | go/cmd/gitlab-shell/main.go | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go index ae54151..07623b4 100644 --- a/go/cmd/gitlab-shell/main.go +++ b/go/cmd/gitlab-shell/main.go @@ -4,8 +4,9 @@ import ( "fmt" "os" "path/filepath" - "syscall" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/command" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/fallback" "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" ) @@ -19,20 +20,12 @@ func init() { 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) + cmd := &fallback.Command{} + if err := cmd.Execute(); err != nil { + fmt.Fprintf(os.Stderr, "Failed to exec: %v\n", err) os.Exit(1) } } @@ -46,11 +39,18 @@ func main() { execRuby() } - // Try to handle the command with the Go implementation - if exitCode, done := migrate(config); done { - os.Exit(exitCode) + cmd, err := command.New(os.Args, config) + if err != nil { + // For now this could happen if `SSH_CONNECTION` is not set on + // the environment + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) } - // Since a migration has not handled the command, fall back to Ruby to do so - execRuby() + // The command will write to STDOUT on execution or replace the current + // process in case of the `fallback.Command` + if err = cmd.Execute(); err != nil { + fmt.Fprintf(os.Stderr, "%v\n", err) + os.Exit(1) + } } |