Skip to content

Commit 6277394

Browse files
authored
Merge pull request #2273 from pratikjagrut/fix.run
fix: don't ask question if devspace is not used in terminal
2 parents 784b957 + 77d89e3 commit 6277394

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

cmd/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package cmd
33
import (
44
"context"
55
"fmt"
6-
"github.com/loft-sh/devspace/pkg/devspace/pipeline/env"
76
"io"
8-
"mvdan.cc/sh/v3/expand"
97
"os"
108
"strings"
119

10+
"github.com/loft-sh/devspace/pkg/devspace/pipeline/env"
11+
"mvdan.cc/sh/v3/expand"
12+
1213
"github.com/loft-sh/devspace/pkg/devspace/config"
1314
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
1415
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"

pkg/devspace/config/loader/loader.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ package loader
33
import (
44
"context"
55
"fmt"
6-
"github.com/loft-sh/devspace/pkg/devspace/context/values"
7-
"github.com/loft-sh/devspace/pkg/util/encoding"
8-
"github.com/loft-sh/devspace/pkg/util/yamlutil"
96
"io/ioutil"
10-
"mvdan.cc/sh/v3/expand"
117
"os"
128
"path/filepath"
139
"regexp"
1410
"strings"
1511

12+
"github.com/loft-sh/devspace/pkg/devspace/context/values"
13+
"github.com/loft-sh/devspace/pkg/util/encoding"
14+
"github.com/loft-sh/devspace/pkg/util/yamlutil"
15+
"mvdan.cc/sh/v3/expand"
16+
1617
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
1718
"github.com/loft-sh/devspace/pkg/devspace/config/remotecache"
1819
"github.com/loft-sh/devspace/pkg/devspace/kubectl"

pkg/devspace/config/loader/variable/undefined_variable.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package variable
33
import (
44
"context"
55
"fmt"
6-
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
7-
"github.com/sirupsen/logrus"
86
"os"
97
"strconv"
108

9+
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
10+
"github.com/sirupsen/logrus"
11+
1112
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
1213
"github.com/loft-sh/devspace/pkg/util/log"
1314
"github.com/loft-sh/devspace/pkg/util/survey"
@@ -93,9 +94,6 @@ func askQuestion(variable *latest.Variable, log log.Logger) (string, error) {
9394

9495
if len(variable.Options) > 0 {
9596
params.Options = variable.Options
96-
if variable.Default == nil {
97-
params.DefaultValue = params.Options[0]
98-
}
9997
} else if variable.ValidationPattern != "" {
10098
params.ValidationRegexPattern = variable.ValidationPattern
10199

pkg/util/log/stream_logger.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,10 @@ func (s *StreamLogger) Question(params *survey.QuestionOptions) (string, error)
516516
s.m.Lock()
517517
defer s.m.Unlock()
518518

519-
if !s.isTerminal {
520-
return "", fmt.Errorf("cannot ask question '%s' because you are not currently using a terminal", params.Question)
519+
if !s.isTerminal && (params.DefaultValue == "" || params.DefaultValue == "<nil>") {
520+
return "", fmt.Errorf("cannot ask question '%s' because currently you're not using devspace in a terminal and default value is also not provided", params.Question)
521+
} else if !s.isTerminal && params.DefaultValue != "" {
522+
return params.DefaultValue, nil
521523
}
522524

523525
// Check if we can ask the question

0 commit comments

Comments
 (0)