Skip to content

Commit 9922222

Browse files
committed
Add force-tty flag
1 parent 8d7d782 commit 9922222

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

cli/login.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func login() *cobra.Command {
2222
Args: cobra.ExactArgs(1),
2323
RunE: func(cmd *cobra.Command, args []string) error {
2424
rawURL := args[0]
25+
forceTty, err := cmd.Flags().GetBool(varForceTty)
26+
if err != nil {
27+
return xerrors.Errorf("get force tty flag: %s", err)
28+
}
29+
2530
if !strings.HasPrefix(rawURL, "http://") && !strings.HasPrefix(rawURL, "https://") {
2631
scheme := "https"
2732
if strings.HasPrefix(rawURL, "localhost") {
@@ -44,7 +49,7 @@ func login() *cobra.Command {
4449
return xerrors.Errorf("has initial user: %w", err)
4550
}
4651
if !hasInitialUser {
47-
if !isTTY(cmd.InOrStdin()) {
52+
if !forceTty && !isTTY(cmd.InOrStdin()) {
4853
return xerrors.New("the initial user cannot be created in non-interactive mode. use the API")
4954
}
5055
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s Your Coder deployment hasn't been set up!\n", color.HiBlackString(">"))

cli/login_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestLogin(t *testing.T) {
2626
console, err := expect.NewConsole(expect.WithStdout(clitest.StdoutLogs(t)))
2727
require.NoError(t, err)
2828
client := coderdtest.New(t)
29-
root, _ := clitest.New(t, "login", client.URL.String())
29+
root, _ := clitest.New(t, "login", client.URL.String(), "--force-tty")
3030
root.SetIn(console.InTty())
3131
root.SetOut(console.OutTty())
3232
go func() {

cli/root.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io"
66
"net/url"
77
"os"
8-
"runtime"
98
"strings"
109

1110
"github.com/fatih/color"
@@ -22,6 +21,7 @@ import (
2221

2322
const (
2423
varGlobalConfig = "global-config"
24+
varForceTty = "force-tty"
2525
)
2626

2727
func Root() *cobra.Command {
@@ -66,6 +66,7 @@ func Root() *cobra.Command {
6666
cmd.AddCommand(users())
6767

6868
cmd.PersistentFlags().String(varGlobalConfig, configdir.LocalConfig("coder"), "Path to the global `coder` config directory")
69+
cmd.PersistentFlags().Bool(varForceTty, false, "Force the `coder` command to run as if connected to a TTY")
6970

7071
return cmd
7172
}
@@ -110,11 +111,6 @@ func createConfig(cmd *cobra.Command) config.Root {
110111
// This accepts a reader to work with Cobra's "InOrStdin"
111112
// function for simple testing.
112113
func isTTY(reader io.Reader) bool {
113-
// TODO(Bryan): Is there a reliable way to check this on windows?
114-
if runtime.GOOS == "windows" {
115-
return true
116-
}
117-
118114
file, ok := reader.(*os.File)
119115
if !ok {
120116
return false

0 commit comments

Comments
 (0)