File tree Expand file tree Collapse file tree 8 files changed +24
-25
lines changed Expand file tree Collapse file tree 8 files changed +24
-25
lines changed Original file line number Diff line number Diff line change @@ -47,3 +47,14 @@ func IsCI() bool {
47
47
ci , err := strconv .ParseBool (os .Getenv ("CI" ))
48
48
return ci && err == nil
49
49
}
50
+
51
+ // GetValueOrDefault gets the value of an environment variable.
52
+ // If it's empty, it will return the given default value instead.
53
+ func GetValueOrDefault (key , def string ) string {
54
+ val := os .Getenv (key )
55
+ if val == "" {
56
+ val = def
57
+ }
58
+
59
+ return val
60
+ }
Original file line number Diff line number Diff line change @@ -197,10 +197,10 @@ func (d *Devbox) Shell(ctx context.Context) error {
197
197
return err
198
198
}
199
199
200
- shellStartTime := os . Getenv ( envir .DevboxShellStartTime )
201
- if shellStartTime == "" {
202
- shellStartTime = telemetry .UnixTimestampFromTime (telemetry .CommandStartTime ())
203
- }
200
+ shellStartTime := envir .GetValueOrDefault (
201
+ envir . DevboxShellStartTime ,
202
+ telemetry .UnixTimestampFromTime (telemetry .CommandStartTime ()),
203
+ )
204
204
205
205
opts := []ShellOption {
206
206
WithHooksFilePath (d .scriptPath (hooksFilename )),
Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ type Recommender struct {
20
20
var _ recommenders.Recommender = (* Recommender )(nil )
21
21
22
22
func (r * Recommender ) IsRelevant () bool {
23
- packageJSONPath := filepath .Join (r .SrcDir , "package.json" )
24
- return fileutil .Exists (packageJSONPath )
23
+ return fileutil .Exists (filepath .Join (r .SrcDir , "package.json" ))
25
24
}
26
25
27
26
func (r * Recommender ) Packages () []string {
@@ -74,8 +73,7 @@ func (r *Recommender) nodeVersion(project *nodeProject) *plansdk.Version {
74
73
}
75
74
76
75
func (r * Recommender ) packageManager () string {
77
- yarnPkgLockPath := filepath .Join (r .SrcDir , "yarn.lock" )
78
- if fileutil .Exists (yarnPkgLockPath ) {
76
+ if fileutil .Exists (filepath .Join (r .SrcDir , "yarn.lock" )) {
79
77
return "yarn"
80
78
}
81
79
return "npm"
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ func (r *RecommenderPoetry) Packages() []string {
39
39
// TODO: This can be generalized to all python planners
40
40
func (r * RecommenderPoetry ) PythonVersion () * plansdk.Version {
41
41
defaultVersion , _ := plansdk .NewVersion ("3.10.6" )
42
- project := r .PyProject ()
42
+ project := r .pyProject ()
43
43
44
44
if project == nil {
45
45
return defaultVersion
@@ -67,7 +67,7 @@ type pyProject struct {
67
67
} `toml:"tool"`
68
68
}
69
69
70
- func (r * RecommenderPoetry ) PyProject () * pyProject {
70
+ func (r * RecommenderPoetry ) pyProject () * pyProject {
71
71
pyProjectPath := filepath .Join (r .SrcDir , "pyproject.toml" )
72
72
content , err := os .ReadFile (pyProjectPath )
73
73
if err != nil {
Original file line number Diff line number Diff line change @@ -64,8 +64,6 @@ func parseRubyVersion(gemfile string) string {
64
64
return matches [2 ]
65
65
}
66
66
}
67
- if err := s .Err (); err != nil {
68
- return ""
69
- }
70
- return "" // not found
67
+
68
+ return ""
71
69
}
Original file line number Diff line number Diff line change @@ -35,11 +35,7 @@ func (v Version) parts() []string {
35
35
}
36
36
37
37
func (v Version ) Exact () string {
38
- parts := v .parts ()
39
- if len (parts ) == 0 {
40
- return ""
41
- }
42
- return strings .Join (parts , "" )
38
+ return strings .Join (v .parts (), "" )
43
39
}
44
40
45
41
func (v Version ) Major () string {
Original file line number Diff line number Diff line change 9
9
"io"
10
10
"net/http"
11
11
"net/url"
12
- "os"
13
12
"strings"
14
13
15
14
"go.jetpack.io/devbox/internal/boxcli/usererr"
@@ -20,11 +19,7 @@ import (
20
19
const searchAPIEndpoint = "https://search.devbox.sh"
21
20
22
21
func searchHost () string {
23
- endpoint := searchAPIEndpoint
24
- if os .Getenv (envir .DevboxSearchHost ) != "" {
25
- endpoint = os .Getenv (envir .DevboxSearchHost )
26
- }
27
- return endpoint
22
+ return envir .GetValueOrDefault (envir .DevboxSearchHost , searchAPIEndpoint )
28
23
}
29
24
30
25
type client struct {
Original file line number Diff line number Diff line change 9
9
"strings"
10
10
11
11
"github.com/samber/lo"
12
+
12
13
"go.jetpack.io/devbox/internal/redact"
13
14
)
14
15
You can’t perform that action at this time.
0 commit comments