Skip to content

Commit

Permalink
print out success/warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitpaulk committed Nov 4, 2022
1 parent bba7229 commit 12a2367
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/codecrafters-io/logstream v0.0.0-20221026224152-2d9b2ed6d71c
github.com/fatih/color v1.13.0
github.com/levigross/grequests v0.0.0-20190908174114-253788527a1a
github.com/mitchellh/go-wordwrap v1.0.1
github.com/otiai10/copy v1.7.0
github.com/stretchr/testify v1.5.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
19 changes: 19 additions & 0 deletions internal/commands/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/codecrafters-io/cli/internal/utils"
logstream_consumer "github.com/codecrafters-io/logstream/consumer"
"github.com/fatih/color"
wordwrap "github.com/mitchellh/go-wordwrap"
cp "github.com/otiai10/copy"
"io"
"io/ioutil"
Expand Down Expand Up @@ -65,6 +66,24 @@ func TestCommand() int {
return 1
}

if createSubmissionResponse.OnInitSuccessMessage != "" {
fmt.Println("")

wrapped := wordwrap.WrapString(createSubmissionResponse.OnInitSuccessMessage, 79)
for _, line := range strings.Split(wrapped, "\n") {
fmt.Println(fmt.Sprintf("\033[1;92m%s\033[0m", line))
}
}

if createSubmissionResponse.OnInitWarningMessage != "" {
fmt.Println("")

wrapped := wordwrap.WrapString(createSubmissionResponse.OnInitWarningMessage, 79)
for _, line := range strings.Split(wrapped, "\n") {
fmt.Println(fmt.Sprintf("\033[31m%s\033[0m", line))
}
}

fmt.Println("")
err = streamLogs(createSubmissionResponse.LogstreamUrl)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions internal/utils/codecrafters_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
)

type CreateSubmissionResponse struct {
Id string `json:"id"`
ErrorMessage string `json:"error_message"`
IsError bool `json:"is_error"`
LogstreamUrl string `json:"logstream_url"`
OnFailureMessage string `json:"on_failure_message"`
OnSuccessMessage string `json:"on_success_message"`
Id string `json:"id"`
ErrorMessage string `json:"error_message"`
IsError bool `json:"is_error"`
LogstreamUrl string `json:"logstream_url"`
OnFailureMessage string `json:"on_failure_message"`
OnSuccessMessage string `json:"on_success_message"`
OnInitSuccessMessage string `json:"on_init_success_message"`
OnInitWarningMessage string `json:"on_init_warning_message"`
}

type FetchSubmissionResponse struct {
Expand Down

0 comments on commit 12a2367

Please sign in to comment.