From 8771741b0c3c1fe348e5578097a097fa3d159d95 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Thu, 22 Jul 2021 10:39:14 -0400 Subject: [PATCH 1/4] cli: Use glint to determine if os.Stdout is tty --- command/deployment_status.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/command/deployment_status.go b/command/deployment_status.go index 8f59b267b1c..3e03ba0c01d 100644 --- a/command/deployment_status.go +++ b/command/deployment_status.go @@ -182,15 +182,28 @@ func (c *DeploymentStatusCommand) Run(args []string) int { } func (c *DeploymentStatusCommand) monitor(client *api.Client, deployID string, index uint64, verbose bool) { - _, isStdoutTerminal := term.GetFdInfo(os.Stdout) - // TODO if/when glint offers full Windows support take out the runtime check - if isStdoutTerminal && runtime.GOOS != "windows" { + if isStdoutTerminal() { c.ttyMonitor(client, deployID, index, verbose) } else { c.defaultMonitor(client, deployID, index, verbose) } } +func isStdoutTerminal() bool { + // TODO if/when glint offers full Windows support take out the runtime check + if runtime.GOOS == "windows" { + return false + } + + // glint checks if the writer is a tty with additional + // checks (e.g. terminal has non-0 size) + r := &glint.TerminalRenderer{ + Output: os.Stdout, + } + + return r.LayoutRoot() != nil +} + // Uses glint for printing in place. Same logic as the defaultMonitor function // but only used for tty and non-Windows machines since glint doesn't work with // cmd/PowerShell and non-interactive interfaces @@ -214,9 +227,10 @@ func (c *DeploymentStatusCommand) ttyMonitor(client *api.Client, deployID string d.Set(spinner) ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + d.RenderFrame() go d.Render(ctx) - defer cancel() q := api.QueryOptions{ AllowStale: true, From 03b30893e886a08d8d9fe63f3a7a39e51780f98a Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Thu, 22 Jul 2021 12:37:46 -0400 Subject: [PATCH 2/4] update go-glint dependency --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c8274c7e50a..4f86bf456dd 100644 --- a/go.mod +++ b/go.mod @@ -98,7 +98,7 @@ require ( github.com/mitchellh/cli v1.1.0 github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286 github.com/mitchellh/copystructure v1.0.0 - github.com/mitchellh/go-glint v0.0.0-20201119015200-53f6eb3bf4d2 + github.com/mitchellh/go-glint v0.0.0-20210722152315-6515ceb4a127 github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b github.com/mitchellh/go-testing-interface v1.14.1 github.com/mitchellh/hashstructure v1.0.0 diff --git a/go.sum b/go.sum index e4463b0d5ca..be4e0308aae 100644 --- a/go.sum +++ b/go.sum @@ -540,8 +540,8 @@ github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286 h1:KHyL+3mQO github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= -github.com/mitchellh/go-glint v0.0.0-20201119015200-53f6eb3bf4d2 h1:p6jvEJYVtY05cbttwUhvxzV1j/e/40musLqs18vkv+E= -github.com/mitchellh/go-glint v0.0.0-20201119015200-53f6eb3bf4d2/go.mod h1:9X3rpO+I3yuihb6p8ktF8qWxROGwij9DBW/czUsMlhk= +github.com/mitchellh/go-glint v0.0.0-20210722152315-6515ceb4a127 h1:/EdGXMUGYFdp0+cmGjVLl/Qbx3G10csqgj22ZkrPFEA= +github.com/mitchellh/go-glint v0.0.0-20210722152315-6515ceb4a127/go.mod h1:9X3rpO+I3yuihb6p8ktF8qWxROGwij9DBW/czUsMlhk= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= From 6ea92e803cdd33e40d0cf605a6e18aca23eb81e0 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Thu, 22 Jul 2021 12:39:12 -0400 Subject: [PATCH 3/4] add changelog --- .changelog/10926.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/10926.txt diff --git a/.changelog/10926.txt b/.changelog/10926.txt new file mode 100644 index 00000000000..e0a19617db8 --- /dev/null +++ b/.changelog/10926.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli: Fixed a panic when deployment monitor is invoked in some CI environments +``` From 65e4cba3927c6a490297d8b3febe202101eb9eac Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Fri, 23 Jul 2021 11:04:31 -0400 Subject: [PATCH 4/4] fixup! update go-glint dependency --- command/deployment_status.go | 1 - 1 file changed, 1 deletion(-) diff --git a/command/deployment_status.go b/command/deployment_status.go index 3e03ba0c01d..18de5e218ce 100644 --- a/command/deployment_status.go +++ b/command/deployment_status.go @@ -229,7 +229,6 @@ func (c *DeploymentStatusCommand) ttyMonitor(client *api.Client, deployID string ctx, cancel := context.WithCancel(context.Background()) defer cancel() - d.RenderFrame() go d.Render(ctx) q := api.QueryOptions{