@@ -2,6 +2,7 @@ package cmd
22
33import (
44 "fmt"
5+ "log"
56 "os"
67 "regexp"
78 "strings"
@@ -13,6 +14,7 @@ import (
1314 "github.com/drycc/workflow-cli/pkg/logging"
1415 "github.com/drycc/workflow-cli/pkg/webbrowser"
1516 "github.com/drycc/workflow-cli/settings"
17+ "github.com/gorilla/websocket"
1618)
1719
1820// AppCreate creates an app.
@@ -158,22 +160,28 @@ func (d *DryccCmd) AppOpen(appID string) error {
158160}
159161
160162// AppLogs returns the logs from an app.
161- func (d * DryccCmd ) AppLogs (appID string , lines int ) error {
163+ func (d * DryccCmd ) AppLogs (appID string , lines int , follow bool , timeout int ) error {
162164 s , appID , err := load (d .ConfigFile , appID )
163165
164166 if err != nil {
165167 return err
166168 }
167169
168- logs , err := apps .Logs (s .Client , appID , lines )
169- if d . checkAPICompatibility ( s . Client , err ) != nil {
170+ conn , err := apps .Logs (s .Client , appID , lines , follow , timeout )
171+ if err != nil {
170172 return err
171173 }
172-
173- for _ , log := range strings .Split (strings .TrimRight (logs , `\n` ), `\n` ) {
174- logging .PrintLog (os .Stdout , log )
174+ defer conn .Close ()
175+ for {
176+ _ , message , err := conn .ReadMessage ()
177+ if err != nil {
178+ if websocket .IsUnexpectedCloseError (err , websocket .CloseGoingAway , websocket .CloseNormalClosure ) {
179+ log .Printf ("error: %v" , err )
180+ }
181+ break
182+ }
183+ logging .PrintLog (os .Stdout , strings .TrimRight (string (message ), "\n " ))
175184 }
176-
177185 return nil
178186}
179187
0 commit comments