Skip to content

Commit 12a2367

Browse files
committed
print out success/warning messages
1 parent bba7229 commit 12a2367

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/codecrafters-io/logstream v0.0.0-20221026224152-2d9b2ed6d71c
88
github.com/fatih/color v1.13.0
99
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a
10+
github.com/mitchellh/go-wordwrap v1.0.1
1011
github.com/otiai10/copy v1.7.0
1112
github.com/stretchr/testify v1.5.1
1213
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
5050
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
5151
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
5252
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
53+
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
54+
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
5355
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
5456
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
5557
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=

internal/commands/test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/codecrafters-io/cli/internal/utils"
66
logstream_consumer "github.com/codecrafters-io/logstream/consumer"
77
"github.com/fatih/color"
8+
wordwrap "github.com/mitchellh/go-wordwrap"
89
cp "github.com/otiai10/copy"
910
"io"
1011
"io/ioutil"
@@ -65,6 +66,24 @@ func TestCommand() int {
6566
return 1
6667
}
6768

69+
if createSubmissionResponse.OnInitSuccessMessage != "" {
70+
fmt.Println("")
71+
72+
wrapped := wordwrap.WrapString(createSubmissionResponse.OnInitSuccessMessage, 79)
73+
for _, line := range strings.Split(wrapped, "\n") {
74+
fmt.Println(fmt.Sprintf("\033[1;92m%s\033[0m", line))
75+
}
76+
}
77+
78+
if createSubmissionResponse.OnInitWarningMessage != "" {
79+
fmt.Println("")
80+
81+
wrapped := wordwrap.WrapString(createSubmissionResponse.OnInitWarningMessage, 79)
82+
for _, line := range strings.Split(wrapped, "\n") {
83+
fmt.Println(fmt.Sprintf("\033[31m%s\033[0m", line))
84+
}
85+
}
86+
6887
fmt.Println("")
6988
err = streamLogs(createSubmissionResponse.LogstreamUrl)
7089
if err != nil {

internal/utils/codecrafters_client.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import (
1111
)
1212

1313
type CreateSubmissionResponse struct {
14-
Id string `json:"id"`
15-
ErrorMessage string `json:"error_message"`
16-
IsError bool `json:"is_error"`
17-
LogstreamUrl string `json:"logstream_url"`
18-
OnFailureMessage string `json:"on_failure_message"`
19-
OnSuccessMessage string `json:"on_success_message"`
14+
Id string `json:"id"`
15+
ErrorMessage string `json:"error_message"`
16+
IsError bool `json:"is_error"`
17+
LogstreamUrl string `json:"logstream_url"`
18+
OnFailureMessage string `json:"on_failure_message"`
19+
OnSuccessMessage string `json:"on_success_message"`
20+
OnInitSuccessMessage string `json:"on_init_success_message"`
21+
OnInitWarningMessage string `json:"on_init_warning_message"`
2022
}
2123

2224
type FetchSubmissionResponse struct {

0 commit comments

Comments
 (0)