Skip to content

feat: show banner when workspace is outdated #4926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix: writer
  • Loading branch information
mtojek committed Nov 7, 2022
commit 4e82d1e047232dfc98471b39c68962cc559508c9
13 changes: 12 additions & 1 deletion cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,25 @@ func isTTY(cmd *cobra.Command) bool {
// This accepts a reader to work with Cobra's "OutOrStdout"
// function for simple testing.
func isTTYOut(cmd *cobra.Command) bool {
return isTTYWriter(cmd, cmd.OutOrStdout)
}

// isTTYErr returns whether the passed reader is a TTY or not.
// This accepts a reader to work with Cobra's "ErrOrStderr"
// function for simple testing.
func isTTYErr(cmd *cobra.Command) bool {
return isTTYWriter(cmd, cmd.ErrOrStderr)
}

func isTTYWriter(cmd *cobra.Command, writer func() io.Writer) bool {
// If the `--force-tty` command is available, and set,
// assume we're in a tty. This is primarily for cases on Windows
// where we may not be able to reliably detect this automatically (ie, tests)
forceTty, err := cmd.Flags().GetBool(varForceTty)
if forceTty && err == nil {
return true
}
file, ok := cmd.OutOrStdout().(*os.File)
file, ok := writer().(*os.File)
if !ok {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func ssh() *cobra.Command {
}

updateWorkspaceBanner, outdated := verifyWorkspaceOutdated(client, workspace)
if outdated && isTTYOut(cmd) {
if outdated && isTTYErr(cmd) {
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), updateWorkspaceBanner)
}

Expand Down