Skip to content

Commit c7a03a1

Browse files
committed
base dir
1 parent c8b451f commit c7a03a1

File tree

3 files changed

+80
-80
lines changed

3 files changed

+80
-80
lines changed

options/defaults.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ func (o *Options) SetDefaults() {
5959
if o.Filesystem == nil {
6060
o.Filesystem = chmodfs.New(osfs.New("/"))
6161
}
62-
if o.WorkspacesFolder == "" {
63-
o.WorkspacesFolder = "/workspaces"
62+
if o.WorkspaceBaseDir == "" {
63+
o.WorkspaceBaseDir = "/workspaces"
6464
}
6565
if o.WorkspaceFolder == "" {
66-
o.WorkspaceFolder = DefaultWorkspaceFolder(o.WorkspacesFolder, o.GitURL)
66+
o.WorkspaceFolder = DefaultWorkspaceFolder(o.WorkspaceBaseDir, o.GitURL)
6767
}
6868
if o.BinaryPath == "" {
6969
o.BinaryPath = "/.envbuilder/bin/envbuilder"

options/defaults_test.go

+70-70
Original file line numberDiff line numberDiff line change
@@ -16,111 +16,111 @@ func TestDefaultWorkspaceFolder(t *testing.T) {
1616
t.Parallel()
1717

1818
successTests := []struct {
19-
name string
20-
workspacesFolder string
21-
gitURL string
22-
expected string
19+
name string
20+
baseDir string
21+
gitURL string
22+
expected string
2323
}{
2424
{
25-
name: "HTTP",
26-
workspacesFolder: "/workspaces",
27-
gitURL: "https://github.com/coder/envbuilder.git",
28-
expected: "/workspaces/envbuilder",
25+
name: "HTTP",
26+
baseDir: "/workspaces",
27+
gitURL: "https://github.com/coder/envbuilder.git",
28+
expected: "/workspaces/envbuilder",
2929
},
3030
{
31-
name: "SSH",
32-
workspacesFolder: "/workspaces",
33-
gitURL: "[email protected]:coder/envbuilder.git",
34-
expected: "/workspaces/envbuilder",
31+
name: "SSH",
32+
baseDir: "/workspaces",
33+
gitURL: "[email protected]:coder/envbuilder.git",
34+
expected: "/workspaces/envbuilder",
3535
},
3636
{
37-
name: "username and password",
38-
workspacesFolder: "/workspaces",
39-
gitURL: "https://username:[email protected]/coder/envbuilder.git",
40-
expected: "/workspaces/envbuilder",
37+
name: "username and password",
38+
baseDir: "/workspaces",
39+
gitURL: "https://username:[email protected]/coder/envbuilder.git",
40+
expected: "/workspaces/envbuilder",
4141
},
4242
{
43-
name: "trailing",
44-
workspacesFolder: "/workspaces",
45-
gitURL: "https://github.com/coder/envbuilder.git/",
46-
expected: "/workspaces/envbuilder",
43+
name: "trailing",
44+
baseDir: "/workspaces",
45+
gitURL: "https://github.com/coder/envbuilder.git/",
46+
expected: "/workspaces/envbuilder",
4747
},
4848
{
49-
name: "trailing-x2",
50-
workspacesFolder: "/workspaces",
51-
gitURL: "https://github.com/coder/envbuilder.git//",
52-
expected: "/workspaces/envbuilder",
49+
name: "trailing-x2",
50+
baseDir: "/workspaces",
51+
gitURL: "https://github.com/coder/envbuilder.git//",
52+
expected: "/workspaces/envbuilder",
5353
},
5454
{
55-
name: "no .git",
56-
workspacesFolder: "/workspaces",
57-
gitURL: "https://github.com/coder/envbuilder",
58-
expected: "/workspaces/envbuilder",
55+
name: "no .git",
56+
baseDir: "/workspaces",
57+
gitURL: "https://github.com/coder/envbuilder",
58+
expected: "/workspaces/envbuilder",
5959
},
6060
{
61-
name: "trailing no .git",
62-
workspacesFolder: "/workspaces",
63-
gitURL: "https://github.com/coder/envbuilder/",
64-
expected: "/workspaces/envbuilder",
61+
name: "trailing no .git",
62+
baseDir: "/workspaces",
63+
gitURL: "https://github.com/coder/envbuilder/",
64+
expected: "/workspaces/envbuilder",
6565
},
6666
{
67-
name: "fragment",
68-
workspacesFolder: "/workspaces",
69-
gitURL: "https://github.com/coder/envbuilder.git#feature-branch",
70-
expected: "/workspaces/envbuilder",
67+
name: "fragment",
68+
baseDir: "/workspaces",
69+
gitURL: "https://github.com/coder/envbuilder.git#feature-branch",
70+
expected: "/workspaces/envbuilder",
7171
},
7272
{
73-
name: "fragment-trailing",
74-
workspacesFolder: "/workspaces",
75-
gitURL: "https://github.com/coder/envbuilder.git/#refs/heads/feature-branch",
76-
expected: "/workspaces/envbuilder",
73+
name: "fragment-trailing",
74+
baseDir: "/workspaces",
75+
gitURL: "https://github.com/coder/envbuilder.git/#refs/heads/feature-branch",
76+
expected: "/workspaces/envbuilder",
7777
},
7878
{
79-
name: "fragment-trailing no .git",
80-
workspacesFolder: "/workspaces",
81-
gitURL: "https://github.com/coder/envbuilder/#refs/heads/feature-branch",
82-
expected: "/workspaces/envbuilder",
79+
name: "fragment-trailing no .git",
80+
baseDir: "/workspaces",
81+
gitURL: "https://github.com/coder/envbuilder/#refs/heads/feature-branch",
82+
expected: "/workspaces/envbuilder",
8383
},
8484
{
85-
name: "space",
86-
workspacesFolder: "/workspaces",
87-
gitURL: "https://github.com/coder/env%20builder.git",
88-
expected: "/workspaces/env builder",
85+
name: "space",
86+
baseDir: "/workspaces",
87+
gitURL: "https://github.com/coder/env%20builder.git",
88+
expected: "/workspaces/env builder",
8989
},
9090
{
91-
name: "Unix path",
92-
workspacesFolder: "/workspaces",
93-
gitURL: "/repo",
94-
expected: "/workspaces/repo",
91+
name: "Unix path",
92+
baseDir: "/workspaces",
93+
gitURL: "/repo",
94+
expected: "/workspaces/repo",
9595
},
9696
{
97-
name: "Unix subpath",
98-
workspacesFolder: "/workspaces",
99-
gitURL: "/path/to/repo",
100-
expected: "/workspaces/repo",
97+
name: "Unix subpath",
98+
baseDir: "/workspaces",
99+
gitURL: "/path/to/repo",
100+
expected: "/workspaces/repo",
101101
},
102102
{
103-
name: "empty",
104-
workspacesFolder: "/workspaces",
105-
gitURL: "",
106-
expected: "/workspaces/empty",
103+
name: "empty",
104+
baseDir: "/workspaces",
105+
gitURL: "",
106+
expected: "/workspaces/empty",
107107
},
108108
{
109-
name: "non default workspaces folder",
110-
workspacesFolder: "/foo",
111-
gitURL: "https://github.com/coder/envbuilder.git",
112-
expected: "/foo/envbuilder",
109+
name: "non default workspaces folder",
110+
baseDir: "/foo",
111+
gitURL: "https://github.com/coder/envbuilder.git",
112+
expected: "/foo/envbuilder",
113113
},
114114
{
115-
name: "non default workspaces folder empty git URL",
116-
workspacesFolder: "/foo",
117-
gitURL: "",
118-
expected: "/foo/empty",
115+
name: "non default workspaces folder empty git URL",
116+
baseDir: "/foo",
117+
gitURL: "",
118+
expected: "/foo/empty",
119119
},
120120
}
121121
for _, tt := range successTests {
122122
t.Run(tt.name, func(t *testing.T) {
123-
dir := options.DefaultWorkspaceFolder(tt.workspacesFolder, tt.gitURL)
123+
dir := options.DefaultWorkspaceFolder(tt.baseDir, tt.gitURL)
124124
require.Equal(t, tt.expected, dir)
125125
})
126126
}
@@ -167,7 +167,7 @@ func TestOptions_SetDefaults(t *testing.T) {
167167
IgnorePaths: []string{"/var/run", "/product_uuid", "/product_name"},
168168
Filesystem: chmodfs.New(osfs.New("/")),
169169
GitURL: "",
170-
WorkspacesFolder: "/workspaces",
170+
WorkspaceBaseDir: "/workspaces",
171171
WorkspaceFolder: "/workspaces/empty",
172172
WorkingDirBase: "/.envbuilder",
173173
BinaryPath: "/.envbuilder/bin/envbuilder",

options/options.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ type Options struct {
117117
// GitHTTPProxyURL is the URL for the HTTP proxy. This is optional.
118118
GitHTTPProxyURL string
119119
// WorkspaceFolder is the path to the workspace folder that will be built.
120-
// This is optional. Defaults to `[workspaces folder]/[name]` where name is
120+
// This is optional. Defaults to `[workspace base dir]/[name]` where name is
121121
// the name of the repository or "empty".
122122
WorkspaceFolder string
123-
// WorkspacesFolder is the path under which workspaces will be placed when
123+
// WorkspaceBaseDir is the path under which workspaces will be placed when
124124
// workspace folder option is not given.
125-
WorkspacesFolder string
125+
WorkspaceBaseDir string
126126
// SSLCertBase64 is the content of an SSL cert file. This is useful for
127127
// self-signed certificates.
128128
SSLCertBase64 string
@@ -400,13 +400,13 @@ func (o *Options) CLI() serpent.OptionSet {
400400
Env: WithEnvPrefix("WORKSPACE_FOLDER"),
401401
Value: serpent.StringOf(&o.WorkspaceFolder),
402402
Description: "The path to the workspace folder that will be built. " +
403-
"This is optional. Defaults to `[workspaces folder]/[name]` where " +
403+
"This is optional. Defaults to `[workspace base dir]/[name]` where " +
404404
"name is the name of the repository or `empty`.",
405405
},
406406
{
407-
Flag: "workspaces-folder",
408-
Env: WithEnvPrefix("WORKSPACES_FOLDER"),
409-
Value: serpent.StringOf(&o.WorkspacesFolder),
407+
Flag: "workspace-base-dir",
408+
Env: WithEnvPrefix("WORKSPACE_BASE_DIR"),
409+
Value: serpent.StringOf(&o.WorkspaceBaseDir),
410410
Default: "/workspaces",
411411
Description: "The path under which workspaces will be placed when " +
412412
"workspace folder option is not given.",

0 commit comments

Comments
 (0)