Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func promptInitConfig() error {
return err
}

if !isPromptTTY() {
fmt.Fprintln(os.Stderr, output.WarnStderr("bight: no config file found and stdin is not a TTY; skipping interactive setup. Create .bight.yml manually or re-run from a terminal."))
return nil
}

if !confirm("bight: no config file found. Create .bight.yml?", true) {
return nil
}
Expand Down
48 changes: 48 additions & 0 deletions cmd/install_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cmd

import (
"os"
"strings"
"testing"
)

func TestPromptInitConfig_NonTTYBailsOut(t *testing.T) {
// Isolate from any real ~/.bight.yml and from the worktree's .bight.yml
// so config.Load() returns os.ErrNotExist.
t.Setenv("HOME", t.TempDir())
t.Chdir(t.TempDir())

withStubPrompt(t, false, "")

if err := promptInitConfig(); err != nil {
t.Fatalf("promptInitConfig: %v", err)
}

if _, err := os.Stat(".bight.yml"); !os.IsNotExist(err) {
t.Errorf("expected no .bight.yml to be written under non-TTY, stat err=%v", err)
}
}

func TestPromptInitConfig_TTYCreatesConfig(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Chdir(t.TempDir())

// Accept "Create .bight.yml?" (Y), accept default project, default env
// file, decline seed, decline add vars.
withStubPrompt(t, true, strings.Join([]string{
"y", // Create .bight.yml?
"", // Project name (default)
"", // Env file path (default)
"n", // Seed from another path?
"n", // Add env vars?
"",
}, "\n"))

if err := promptInitConfig(); err != nil {
t.Fatalf("promptInitConfig: %v", err)
}

if _, err := os.Stat(".bight.yml"); err != nil {
t.Errorf("expected .bight.yml to be written under TTY: %v", err)
}
}