diff --git a/go.mod b/go.mod index e80cae3..c8c7676 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 3bc36db..7be38cc 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/commands/test.go b/internal/commands/test.go index f0eadaf..7261a8f 100644 --- a/internal/commands/test.go +++ b/internal/commands/test.go @@ -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" @@ -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 { diff --git a/internal/utils/codecrafters_client.go b/internal/utils/codecrafters_client.go index 4e59e2b..d31908b 100644 --- a/internal/utils/codecrafters_client.go +++ b/internal/utils/codecrafters_client.go @@ -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 {