summaryrefslogtreecommitdiff
path: root/go/internal/command
diff options
context:
space:
mode:
Diffstat (limited to 'go/internal/command')
-rw-r--r--go/internal/command/command.go3
-rw-r--r--go/internal/command/discover/discover.go13
-rw-r--r--go/internal/command/discover/discover_test.go11
-rw-r--r--go/internal/command/fallback/fallback.go4
-rw-r--r--go/internal/command/reporting/reporter.go8
5 files changed, 23 insertions, 16 deletions
diff --git a/go/internal/command/command.go b/go/internal/command/command.go
index cb2acdc..d4649de 100644
--- a/go/internal/command/command.go
+++ b/go/internal/command/command.go
@@ -4,11 +4,12 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/discover"
"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"
)
type Command interface {
- Execute() error
+ Execute(*reporting.Reporter) error
}
func New(arguments []string, config *config.Config) (Command, error) {
diff --git a/go/internal/command/discover/discover.go b/go/internal/command/discover/discover.go
index ab04cbd..8ad2868 100644
--- a/go/internal/command/discover/discover.go
+++ b/go/internal/command/discover/discover.go
@@ -2,10 +2,9 @@ package discover
import (
"fmt"
- "io"
- "os"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/reporting"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/discover"
)
@@ -15,20 +14,16 @@ type Command struct {
Args *commandargs.CommandArgs
}
-var (
- output io.Writer = os.Stdout
-)
-
-func (c *Command) Execute() error {
+func (c *Command) Execute(reporter *reporting.Reporter) error {
response, err := c.getUserInfo()
if err != nil {
return fmt.Errorf("Failed to get username: %v", err)
}
if response.IsAnonymous() {
- fmt.Fprintf(output, "Welcome to GitLab, Anonymous!\n")
+ fmt.Fprintf(reporter.Out, "Welcome to GitLab, Anonymous!\n")
} else {
- fmt.Fprintf(output, "Welcome to GitLab, @%s!\n", response.Username)
+ fmt.Fprintf(reporter.Out, "Welcome to GitLab, @%s!\n", response.Username)
}
return nil
diff --git a/go/internal/command/discover/discover_test.go b/go/internal/command/discover/discover_test.go
index 752e76e..ec6f931 100644
--- a/go/internal/command/discover/discover_test.go
+++ b/go/internal/command/discover/discover_test.go
@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs"
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/reporting"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/testserver"
)
@@ -78,11 +79,10 @@ func TestExecute(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- buffer := &bytes.Buffer{}
- output = buffer
cmd := &Command{Config: testConfig, Args: tc.arguments}
+ buffer := &bytes.Buffer{}
- err := cmd.Execute()
+ err := cmd.Execute(&reporting.Reporter{Out: buffer})
assert.NoError(t, err)
assert.Equal(t, tc.expectedOutput, buffer.String())
@@ -120,11 +120,12 @@ func TestFailingExecute(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
cmd := &Command{Config: testConfig, Args: tc.arguments}
+ buffer := &bytes.Buffer{}
- err := cmd.Execute()
+ err := cmd.Execute(&reporting.Reporter{Out: buffer})
+ assert.Empty(t, buffer.String())
assert.EqualError(t, err, tc.expectedError)
})
}
-
}
diff --git a/go/internal/command/fallback/fallback.go b/go/internal/command/fallback/fallback.go
index a136657..a2c73ed 100644
--- a/go/internal/command/fallback/fallback.go
+++ b/go/internal/command/fallback/fallback.go
@@ -4,6 +4,8 @@ import (
"os"
"path/filepath"
"syscall"
+
+ "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/reporting"
)
type Command struct{}
@@ -12,7 +14,7 @@ var (
binDir = filepath.Dir(os.Args[0])
)
-func (c *Command) Execute() error {
+func (c *Command) Execute(_ *reporting.Reporter) error {
rubyCmd := filepath.Join(binDir, "gitlab-shell-ruby")
execErr := syscall.Exec(rubyCmd, os.Args, os.Environ())
return execErr
diff --git a/go/internal/command/reporting/reporter.go b/go/internal/command/reporting/reporter.go
new file mode 100644
index 0000000..74bca59
--- /dev/null
+++ b/go/internal/command/reporting/reporter.go
@@ -0,0 +1,8 @@
+package reporting
+
+import "io"
+
+type Reporter struct {
+ Out io.Writer
+ ErrOut io.Writer
+}