diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-08-02 16:10:17 +0800 |
---|---|---|
committer | Patrick Bajao <ebajao@gitlab.com> | 2019-08-02 16:10:17 +0800 |
commit | 3b6f9f7583755e041e76142d7caf7716937907fa (patch) | |
tree | ed7f7281633d97933e4465a2ac0f86d62c9a216e /go/cmd/gitlab-shell/main.go | |
parent | 592823d5e25006331b361b36cc61df7802fc1938 (diff) | |
download | gitlab-shell-3b6f9f7583755e041e76142d7caf7716937907fa.tar.gz |
Add Executable struct181-migrate-gitlab-shell-checks-fallback
This struct is responsible for determining the name and
root dir of the executable.
The `RootDir` property will be used to find the config.
The `Name` property will be used to determine what `Command`
and `CommandArgs` to be built.
Diffstat (limited to 'go/cmd/gitlab-shell/main.go')
-rw-r--r-- | go/cmd/gitlab-shell/main.go | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go index be388d3..b716820 100644 --- a/go/cmd/gitlab-shell/main.go +++ b/go/cmd/gitlab-shell/main.go @@ -3,30 +3,13 @@ package main import ( "fmt" "os" - "path/filepath" "gitlab.com/gitlab-org/gitlab-shell/go/internal/command" "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/executable" ) -// findRootDir determines the root directory (and so, the location of the config -// file) from os.Executable() -func findRootDir() (string, error) { - if path := os.Getenv("GITLAB_SHELL_DIR"); path != "" { - return path, nil - } - - path, err := os.Executable() - if err != nil { - return "", err - } - - // Start: /opt/.../gitlab-shell/bin/gitlab-shell - // Ends: /opt/.../gitlab-shell - return filepath.Dir(filepath.Dir(path)), nil -} - func main() { readWriter := &readwriter.ReadWriter{ Out: os.Stdout, @@ -34,19 +17,19 @@ func main() { ErrOut: os.Stderr, } - rootDir, err := findRootDir() + executable, err := executable.New() if err != nil { - fmt.Fprintln(readWriter.ErrOut, "Failed to determine root directory, exiting") + fmt.Fprintln(readWriter.ErrOut, "Failed to determine executable, exiting") os.Exit(1) } - config, err := config.NewFromDir(rootDir) + config, err := config.NewFromDir(executable.RootDir) if err != nil { fmt.Fprintln(readWriter.ErrOut, "Failed to read config, exiting") os.Exit(1) } - cmd, err := command.New(os.Args, config, readWriter) + cmd, err := command.New(executable, os.Args[1:], config, readWriter) if err != nil { // For now this could happen if `SSH_CONNECTION` is not set on // the environment |