summaryrefslogtreecommitdiff
path: root/go/cmd/gitlab-shell
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2019-03-14 14:01:42 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2019-03-15 18:03:35 +0100
commit83c0f18e1de04b3bad9c424084e738e911c47336 (patch)
tree22d69b9450693bb153e58dbe8b7cd6feb3f8e1e0 /go/cmd/gitlab-shell
parent53511f3655a5eed9976164fbd88d14df3490000c (diff)
downloadgitlab-shell-83c0f18e1de04b3bad9c424084e738e911c47336.tar.gz
Wrap Stderr & Stdout in a reporter struct
The reporter struct can be used for passing around and reporting to the io.Writer of choice.
Diffstat (limited to 'go/cmd/gitlab-shell')
-rw-r--r--go/cmd/gitlab-shell/main.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/go/cmd/gitlab-shell/main.go b/go/cmd/gitlab-shell/main.go
index 07623b4..2ed319d 100644
--- a/go/cmd/gitlab-shell/main.go
+++ b/go/cmd/gitlab-shell/main.go
@@ -7,25 +7,28 @@ import (
"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/command/reporting"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
)
var (
- binDir string
- rootDir string
+ binDir string
+ rootDir string
+ reporter *reporting.Reporter
)
func init() {
binDir = filepath.Dir(os.Args[0])
rootDir = filepath.Dir(binDir)
+ reporter = &reporting.Reporter{Out: os.Stdout, ErrOut: os.Stderr}
}
// rubyExec will never return. It either replaces the current process with a
// Ruby interpreter, or outputs an error and kills the process.
func execRuby() {
cmd := &fallback.Command{}
- if err := cmd.Execute(); err != nil {
- fmt.Fprintf(os.Stderr, "Failed to exec: %v\n", err)
+ if err := cmd.Execute(reporter); err != nil {
+ fmt.Fprintf(reporter.ErrOut, "Failed to exec: %v\n", err)
os.Exit(1)
}
}
@@ -35,7 +38,7 @@ func main() {
// 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")
+ fmt.Fprintln(reporter.ErrOut, "Failed to read config, falling back to gitlab-shell-ruby")
execRuby()
}
@@ -43,14 +46,14 @@ func main() {
if err != nil {
// For now this could happen if `SSH_CONNECTION` is not set on
// the environment
- fmt.Fprintf(os.Stderr, "%v\n", err)
+ fmt.Fprintf(reporter.ErrOut, "%v\n", err)
os.Exit(1)
}
// 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)
+ if err = cmd.Execute(reporter); err != nil {
+ fmt.Fprintf(reporter.ErrOut, "%v\n", err)
os.Exit(1)
}
}