Commit 1bade9e1 authored by Ash McKenzie's avatar Ash McKenzie Committed by Igor Drozdov

More consistent console messages (golang)

parent 412ed17c
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command" "gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config" "gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/internal/executable"
) )
...@@ -38,7 +39,7 @@ func main() { ...@@ -38,7 +39,7 @@ func main() {
} }
if err = cmd.Execute(); err != nil { if err = cmd.Execute(); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err) console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1) os.Exit(1)
} }
} }
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command" "gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config" "gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/internal/executable"
) )
...@@ -38,7 +39,7 @@ func main() { ...@@ -38,7 +39,7 @@ func main() {
} }
if err = cmd.Execute(); err != nil { if err = cmd.Execute(); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err) console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1) os.Exit(1)
} }
} }
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/command" "gitlab.com/gitlab-org/gitlab-shell/internal/command"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config" "gitlab.com/gitlab-org/gitlab-shell/internal/config"
"gitlab.com/gitlab-org/gitlab-shell/internal/console"
"gitlab.com/gitlab-org/gitlab-shell/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/internal/executable"
) )
...@@ -38,7 +39,7 @@ func main() { ...@@ -38,7 +39,7 @@ func main() {
} }
if err = cmd.Execute(); err != nil { if err = cmd.Execute(); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err) console.DisplayWarningMessage(err.Error(), readWriter.ErrOut)
os.Exit(1) os.Exit(1)
} }
} }
...@@ -31,12 +31,12 @@ func TestFailedRequests(t *testing.T) { ...@@ -31,12 +31,12 @@ func TestFailedRequests(t *testing.T) {
{ {
desc: "With missing arguments", desc: "With missing arguments",
arguments: &commandargs.Shell{}, arguments: &commandargs.Shell{},
expectedOutput: "> GitLab: Disallowed command", expectedOutput: "Disallowed command",
}, },
{ {
desc: "With disallowed command", desc: "With disallowed command",
arguments: &commandargs.Shell{GitlabKeyId: "1", SshArgs: []string{"git-lfs-authenticate", "group/repo", "unknown"}}, arguments: &commandargs.Shell{GitlabKeyId: "1", SshArgs: []string{"git-lfs-authenticate", "group/repo", "unknown"}},
expectedOutput: "> GitLab: Disallowed command", expectedOutput: "Disallowed command",
}, },
{ {
desc: "With disallowed user", desc: "With disallowed user",
......
...@@ -3,12 +3,13 @@ package receivepack ...@@ -3,12 +3,13 @@ package receivepack
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "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"
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier" "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
) )
...@@ -32,19 +33,11 @@ func (c *Command) processCustomAction(response *accessverifier.Response) error { ...@@ -32,19 +33,11 @@ func (c *Command) processCustomAction(response *accessverifier.Response) error {
return errors.New("Custom action error: Empty API endpoints") 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) 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 { func (c *Command) processApiEndpoints(response *accessverifier.Response) error {
client, err := gitlabnet.GetClient(c.Config) client, err := gitlabnet.GetClient(c.Config)
......
...@@ -100,6 +100,6 @@ func TestCustomReceivePack(t *testing.T) { ...@@ -100,6 +100,6 @@ func TestCustomReceivePack(t *testing.T) {
// expect printing of info message, "custom" string from the first request // expect printing of info message, "custom" string from the first request
// and "output" string from the second 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()) require.Equal(t, "customoutput", outBuf.String())
} }
...@@ -2,11 +2,11 @@ package accessverifier ...@@ -2,11 +2,11 @@ package accessverifier
import ( import (
"errors" "errors"
"fmt"
"gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs" "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/command/readwriter"
"gitlab.com/gitlab-org/gitlab-shell/internal/config" "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" "gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/accessverifier"
) )
...@@ -39,7 +39,5 @@ func (c *Command) Verify(action commandargs.CommandType, repo string) (*Response ...@@ -39,7 +39,5 @@ func (c *Command) Verify(action commandargs.CommandType, repo string) (*Response
} }
func (c *Command) displayConsoleMessages(messages []string) { func (c *Command) displayConsoleMessages(messages []string) {
for _, msg := range messages { console.DisplayInfoMessages(messages, c.ReadWriter.ErrOut)
fmt.Fprintf(c.ReadWriter.ErrOut, "> GitLab: %v\n", msg)
}
} }
...@@ -77,6 +77,6 @@ func TestConsoleMessages(t *testing.T) { ...@@ -77,6 +77,6 @@ func TestConsoleMessages(t *testing.T) {
cmd.Args = &commandargs.Shell{GitlabKeyId: "1"} cmd.Args = &commandargs.Shell{GitlabKeyId: "1"}
cmd.Verify(action, repo) 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()) require.Empty(t, outBuf.String())
} }
...@@ -3,5 +3,5 @@ package disallowedcommand ...@@ -3,5 +3,5 @@ package disallowedcommand
import "errors" import "errors"
var ( var (
Error = errors.New("> GitLab: Disallowed command") Error = errors.New("Disallowed command")
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment