summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2019-09-11 23:01:40 +1000
committerIgor Drozdov <idrozdov@gitlab.com>2019-10-23 11:07:22 +0300
commit1bade9e198f08437ad150e63dc751edb862a6f51 (patch)
treeddc792be9340130c00cbac2faa30a1da1ccf7428
parent412ed17cc66d876c46ee8df3767066ca0e676f28 (diff)
downloadgitlab-shell-1bade9e198f08437ad150e63dc751edb862a6f51.tar.gz
More consistent console messages (golang)
-rw-r--r--cmd/gitlab-shell-authorized-keys-check/main.go3
-rw-r--r--cmd/gitlab-shell-authorized-principals-check/main.go3
-rw-r--r--cmd/gitlab-shell/main.go3
-rw-r--r--internal/command/lfsauthenticate/lfsauthenticate_test.go4
-rw-r--r--internal/command/receivepack/customaction.go13
-rw-r--r--internal/command/receivepack/customaction_test.go2
-rw-r--r--internal/command/shared/accessverifier/accessverifier.go6
-rw-r--r--internal/command/shared/accessverifier/accessverifier_test.go2
-rw-r--r--internal/command/shared/disallowedcommand/disallowedcommand.go2
9 files changed, 16 insertions, 22 deletions
diff --git a/cmd/gitlab-shell-authorized-keys-check/main.go b/cmd/gitlab-shell-authorized-keys-check/main.go
index 6b52181..8cc0bc8 100644
--- a/cmd/gitlab-shell-authorized-keys-check/main.go
+++ b/cmd/gitlab-shell-authorized-keys-check/main.go
@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable"
)
@@ -38,7 +39,7 @@ func main() {
}
if err = cmd.Execute(); err != nil {
- fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
+ console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1)
}
}
diff --git a/cmd/gitlab-shell-authorized-principals-check/main.go b/cmd/gitlab-shell-authorized-principals-check/main.go
index 645ccf0..328e11f 100644
--- a/cmd/gitlab-shell-authorized-principals-check/main.go
+++ b/cmd/gitlab-shell-authorized-principals-check/main.go
@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable"
)
@@ -38,7 +39,7 @@ func main() {
}
if err = cmd.Execute(); err != nil {
- fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
+ console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1)
}
}
diff --git a/cmd/gitlab-shell/main.go b/cmd/gitlab-shell/main.go
index 148c652..7751e4d 100644
--- a/cmd/gitlab-shell/main.go
+++ b/cmd/gitlab-shell/main.go
@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable"
)
@@ -38,7 +39,7 @@ func main() {
}
if err = cmd.Execute(); err != nil {
- fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
+ console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1)
}
}
diff --git a/internal/command/lfsauthenticate/lfsauthenticate_test.go b/internal/command/lfsauthenticate/lfsauthenticate_test.go
index f2ccc20..22e151a 100644
--- a/internal/command/lfsauthenticate/lfsauthenticate_test.go
+++ b/internal/command/lfsauthenticate/lfsauthenticate_test.go
@@ -31,12 +31,12 @@ func TestFailedRequests(t *testing.T) {
{
desc: "With missing arguments",
arguments: &commandargs.Shell{},
- expectedOutput: "> GitLab: Disallowed command",
+ expectedOutput: "Disallowed command",
},
{
desc: "With disallowed command",
arguments: &commandargs.Shell{GitlabKeyId: "1", SshArgs: []string{"git-lfs-authenticate", "group/repo", "unknown"}},
- expectedOutput: "> GitLab: Disallowed command",
+ expectedOutput: "Disallowed command",
},
{
desc: "With disallowed user",
diff --git a/internal/command/receivepack/customaction.go b/internal/command/receivepack/customaction.go
index c94ae4c..7575ee9 100644
--- a/internal/command/receivepack/customaction.go
+++ b/internal/command/receivepack/customaction.go
@@ -3,12 +3,13 @@ package receivepack
import (
"bytes"
"errors"
- "fmt"
+
"io"
"io/ioutil"
"net/http"
"strings"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
)
@@ -32,19 +33,11 @@ func (c *Command) processCustomAction(response *accessverifier.Response) error {
return errors.New("Custom action error: Empty API endpoints")
}
- c.displayInfoMessage(data.InfoMessage)
+ console.DisplayInfoMessages(strings.Split(data.InfoMessage, "\n"), c.ReadWriter.ErrOut)
return c.processApiEndpoints(response)
}
-func (c *Command) displayInfoMessage(infoMessage string) {
- messages := strings.Split(infoMessage, "\n")
-
- for _, msg := range messages {
- fmt.Fprintf(c.ReadWriter.ErrOut, "> GitLab: %v\n", msg)
- }
-}
-
func (c *Command) processApiEndpoints(response *accessverifier.Response) error {
client, err := gitlabnet.GetClient(c.Config)
diff --git a/internal/command/receivepack/customaction_test.go b/internal/command/receivepack/customaction_test.go
index 2a4a718..11e7dce 100644
--- a/internal/command/receivepack/customaction_test.go
+++ b/internal/command/receivepack/customaction_test.go
@@ -100,6 +100,6 @@ func TestCustomReceivePack(t *testing.T) {
// expect printing of info message, "custom" string from the first request
// and "output" string from the second request
- require.Equal(t, "> GitLab: info_message\n> GitLab: one more message\n", errBuf.String())
+ require.Equal(t, "remote: \nremote: info_message\nremote: one more message\nremote: \n", errBuf.String())
require.Equal(t, "customoutput", outBuf.String())
}
diff --git a/internal/command/shared/accessverifier/accessverifier.go b/internal/command/shared/accessverifier/accessverifier.go
index 3aaf98d..5d2d709 100644
--- a/internal/command/shared/accessverifier/accessverifier.go
+++ b/internal/command/shared/accessverifier/accessverifier.go
@@ -2,11 +2,11 @@ package accessverifier
import (
"errors"
- "fmt"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config"
+ "gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
)
@@ -39,7 +39,5 @@ func (c *Command) Verify(action commandargs.CommandType, repo string) (*Response
}
func (c *Command) displayConsoleMessages(messages []string) {
- for _, msg := range messages {
- fmt.Fprintf(c.ReadWriter.ErrOut, "> GitLab: %v\n", msg)
- }
+ console.DisplayInfoMessages(messages, c.ReadWriter.ErrOut)
}
diff --git a/internal/command/shared/accessverifier/accessverifier_test.go b/internal/command/shared/accessverifier/accessverifier_test.go
index 39c2a66..cfcf4a8 100644
--- a/internal/command/shared/accessverifier/accessverifier_test.go
+++ b/internal/command/shared/accessverifier/accessverifier_test.go
@@ -77,6 +77,6 @@ func TestConsoleMessages(t *testing.T) {
cmd.Args = &commandargs.Shell{GitlabKeyId: "1"}
cmd.Verify(action, repo)
- require.Equal(t, "> GitLab: console\n> GitLab: message\n", errBuf.String())
+ require.Equal(t, "remote: \nremote: console\nremote: message\nremote: \n", errBuf.String())
require.Empty(t, outBuf.String())
}
diff --git a/internal/command/shared/disallowedcommand/disallowedcommand.go b/internal/command/shared/disallowedcommand/disallowedcommand.go
index 3c98bcc..794944f 100644
--- a/internal/command/shared/disallowedcommand/disallowedcommand.go
+++ b/internal/command/shared/disallowedcommand/disallowedcommand.go
@@ -3,5 +3,5 @@ package disallowedcommand
import "errors"
var (
- Error = errors.New("> GitLab: Disallowed command")
+ Error = errors.New("Disallowed command")
)