Skip to content

Commit 3168e9c

Browse files
committed
Support namespace:name syntax for packages.
This will be needed for languages like Go that have slashes in package names. Keep the legacy namespace/name syntax around for backward-compatibility.
1 parent 8ec8759 commit 3168e9c

File tree

7 files changed

+60
-17
lines changed

7 files changed

+60
-17
lines changed

internal/captain/values.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ func (u *UsersValue) Type() string {
123123
// - <name>
124124
// - <namespace>/<name>
125125
// - <namespace>/<name>@<version>
126+
// - <namespace>:<name>
127+
// - <namespace>:<name>@<version>
126128
type PackageValue struct {
127129
Namespace string `json:"namespace"`
128130
Name string `json:"name"`
@@ -137,7 +139,7 @@ func (p *PackageValue) String() string {
137139
}
138140
name := p.Name
139141
if p.Namespace != "" {
140-
name = fmt.Sprintf("%s/%s", p.Namespace, p.Name)
142+
name = fmt.Sprintf("%s:%s", p.Namespace, p.Name)
141143
}
142144
if p.Version == "" {
143145
return name
@@ -151,13 +153,18 @@ func (p *PackageValue) Set(s string) error {
151153
p.Version = strings.TrimSpace(v[1])
152154
s = v[0]
153155
}
154-
if !strings.Contains(s, "/") {
156+
switch {
157+
case strings.Contains(s, ":"):
158+
v := strings.Split(s, ":")
159+
p.Namespace = strings.TrimSpace(strings.Join(v[0:len(v)-1], ":"))
160+
p.Name = strings.TrimSpace(v[len(v)-1])
161+
case strings.Contains(s, "/"):
162+
v := strings.Split(s, "/")
163+
p.Namespace = strings.TrimSpace(strings.Join(v[0:len(v)-1], "/"))
164+
p.Name = strings.TrimSpace(v[len(v)-1])
165+
default:
155166
p.Name = strings.TrimSpace(s)
156-
return nil
157167
}
158-
v := strings.Split(s, "/")
159-
p.Namespace = strings.TrimSpace(strings.Join(v[0:len(v)-1], "/"))
160-
p.Name = strings.TrimSpace(v[len(v)-1])
161168
return nil
162169
}
163170

internal/captain/values_test.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,30 @@ func TestPackageValue_Set(t *testing.T) {
5353
}{
5454
{
5555
"namespace, name and version",
56-
"namespace/path/name@1.0.0",
56+
"namespace/path:name@1.0.0",
5757
false,
5858
&PackageValue{Namespace: "namespace/path", Name: "name", Version: "1.0.0"},
5959
},
6060
{
6161
"namespace and name",
62+
"namespace/path:name",
63+
false,
64+
&PackageValue{Namespace: "namespace/path", Name: "name"},
65+
},
66+
{
67+
"namespace, name with slashes, and version",
68+
"namespace/path:name/with/slashes@1.0.0",
69+
false,
70+
&PackageValue{Namespace: "namespace/path", Name: "name/with/slashes", Version: "1.0.0"},
71+
},
72+
{
73+
"legacy namespace, name and version",
74+
"namespace/path/name@1.0.0",
75+
false,
76+
&PackageValue{Namespace: "namespace/path", Name: "name", Version: "1.0.0"},
77+
},
78+
{
79+
"legacy namespace and name",
6280
"namespace/path/name",
6381
false,
6482
&PackageValue{Namespace: "namespace/path", Name: "name"},
@@ -99,12 +117,30 @@ func TestPackageFlagNSRequired_Set(t *testing.T) {
99117
}{
100118
{
101119
"namespace, name and version",
102-
"namespace/path/name@1.0.0",
120+
"namespace/path:name@1.0.0",
103121
false,
104122
&PackageValueNSRequired{PackageValue{Namespace: "namespace/path", Name: "name", Version: "1.0.0"}},
105123
},
106124
{
107125
"namespace and name",
126+
"namespace/path:name",
127+
false,
128+
&PackageValueNSRequired{PackageValue{Namespace: "namespace/path", Name: "name"}},
129+
},
130+
{
131+
"namespace and name with slashes",
132+
"namespace/path:name/with/slashes",
133+
false,
134+
&PackageValueNSRequired{PackageValue{Namespace: "namespace/path", Name: "name/with/slashes"}},
135+
},
136+
{
137+
"legacy namespace, name and version",
138+
"namespace/path/name@1.0.0",
139+
false,
140+
&PackageValueNSRequired{PackageValue{Namespace: "namespace/path", Name: "name", Version: "1.0.0"}},
141+
},
142+
{
143+
"legacy namespace and name",
108144
"namespace/path/name",
109145
false,
110146
&PackageValueNSRequired{PackageValue{Namespace: "namespace/path", Name: "name"}},

internal/locale/locales/en-us.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ uploadingredient_success:
14271427
Revision: [ACTIONABLE]{{.V3}}[/RESET]
14281428
Timestamp: [ACTIONABLE]{{.V4}}[/RESET]
14291429
1430-
You can install this package by running `[ACTIONABLE]state install {{.V1}}/{{.V0}} --ts now`[/RESET].
1430+
You can install this package by running `[ACTIONABLE]state install {{.V1}}:{{.V0}} --ts now`[/RESET].
14311431
err_runtime_cache_invalid:
14321432
other: Your runtime needs to be updated. Please run '[ACTIONABLE]state refresh[/RESET]'.
14331433
err_buildscript_not_exist:

test/integration/package_int_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ func (suite *PackageIntegrationTestSuite) TestPackage_Duplicate() {
304304

305305
ts.PrepareEmptyProject()
306306

307-
cp := ts.Spawn("install", "shared/zlib") // install
307+
cp := ts.Spawn("install", "shared:zlib") // install
308308
cp.ExpectExitCode(0)
309309

310-
cp = ts.Spawn("install", "shared/zlib") // install again
310+
cp = ts.Spawn("install", "shared:zlib") // install again
311311
cp.Expect(" no changes")
312312
cp.ExpectNotExitCode(0)
313313
ts.IgnoreLogErrors()
@@ -663,7 +663,7 @@ func (suite *PackageIntegrationTestSuite) TestCVE_Indirect() {
663663
cp = ts.Spawn("config", "set", constants.SecurityPromptConfig, "true")
664664
cp.ExpectExitCode(0)
665665

666-
cp = ts.Spawn("install", "private/ActiveState-CLI-Testing/language/python/django_dep", "--ts=2024-09-10T16:36:34.393Z")
666+
cp = ts.Spawn("install", "private/ActiveState-CLI-Testing/language/python:django_dep", "--ts=2024-09-10T16:36:34.393Z")
667667
cp.ExpectRe(`Warning: Found \d+ indirect known vulnerabilities`, e2e.RuntimeSolvingTimeoutOpt)
668668
cp.Expect("Do you want to continue")
669669
cp.SendLine("n")

test/integration/pull_int_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (suite *PullIntegrationTestSuite) TestMergeBuildScript() {
8989
cp.Expect("Checked out")
9090
cp.ExpectExitCode(0)
9191

92-
cp = ts.Spawn("install", "shared/zlib")
92+
cp = ts.Spawn("install", "shared:zlib")
9393
cp.Expect("Added", e2e.RuntimeSourcingTimeoutOpt)
9494
cp.ExpectExitCode(0)
9595

test/integration/reset_int_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (suite *ResetIntegrationTestSuite) TestReset() {
2929
cp := ts.Spawn("config", "set", constants.AsyncRuntimeConfig, "true")
3030
cp.ExpectExitCode(0)
3131

32-
cp = ts.Spawn("install", "shared/zlib")
32+
cp = ts.Spawn("install", "shared:zlib")
3333
cp.Expect("Added")
3434
cp.ExpectExitCode(0)
3535

@@ -84,7 +84,7 @@ func (suite *ResetIntegrationTestSuite) TestRevertInvalidURL() {
8484
err = fileutils.WriteFile(filepath.Join(ts.Dirs.Work, constants.ConfigFileName), contents)
8585
suite.Require().NoError(err)
8686

87-
cp := ts.Spawn("install", "language/python/requests")
87+
cp := ts.Spawn("install", "language/python:requests")
8888
cp.Expect("invalid commit ID")
8989
cp.Expect("Please run 'state reset' to fix it.")
9090
cp.ExpectNotExitCode(0)

test/integration/runtime_int_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (suite *RuntimeIntegrationTestSuite) TestBuildInProgress() {
169169

170170
ts.PrepareEmptyProject()
171171

172-
cp = ts.Spawn("install", "private/"+e2e.PersistentUsername+"/hello-world", "--ts", "now")
172+
cp = ts.Spawn("install", "private/"+e2e.PersistentUsername+":hello-world", "--ts", "now")
173173
cp.Expect("Build Log:")
174174
cp.Expect("Detailed Progress:")
175175
cp.Expect("Building")
@@ -217,7 +217,7 @@ func (suite *RuntimeIntegrationTestSuite) TestRuntimeCache() {
217217

218218
ts.PrepareEmptyProject()
219219

220-
cp := ts.Spawn("install", "shared/zlib")
220+
cp := ts.Spawn("install", "shared:zlib")
221221
cp.Expect("Downloading")
222222
cp.ExpectExitCode(0)
223223

0 commit comments

Comments
 (0)