Skip to content

Commit 6abc8a2

Browse files
committed
feat: add a diagnostic for the invalid flag when add oci ref
Signed-off-by: zongz <[email protected]>
1 parent d174d9c commit 6abc8a2

File tree

22 files changed

+49
-3
lines changed

22 files changed

+49
-3
lines changed

cmd/kcl/commands/mod_add.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,23 @@ func parseAddOptions(cli *client.KpmClient, localPath string, args []string) (*o
226226
regOpt.Git.Branch = branch
227227
} else if regOpt.Oci != nil && len(tag) != 0 {
228228
regOpt.Oci.Tag = tag
229+
} else if regOpt.Registry != nil {
230+
var invalidFlag string
231+
if len(tag) != 0 {
232+
invalidFlag = tag
233+
} else if len(commit) != 0 {
234+
invalidFlag = commit
235+
} else if len(branch) != 0 {
236+
invalidFlag = branch
237+
}
238+
var diagMsg string
239+
if len(invalidFlag) != 0 {
240+
diagMsg = fmt.Sprintf("invalid flag '%s' for oci registry ref", invalidFlag)
241+
}
242+
if len(tag) != 0 {
243+
diagMsg = fmt.Sprintf("%s, try 'kcl mod add %s:%s'", diagMsg, pkgSource, tag)
244+
}
245+
return nil, fmt.Errorf(diagMsg)
229246
}
230247

231248
return &opt.AddOptions{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/containerd/errdefs v0.1.0 // indirect
2828
github.com/containerd/log v0.1.0 // indirect
2929
github.com/containerd/platforms v0.2.1 // indirect
30-
github.com/containers/image/v5 v5.32.1 // indirect
30+
github.com/containers/image/v5 v5.32.2 // indirect
3131
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
3232
github.com/containers/ocicrypt v1.2.0 // indirect
3333
github.com/containers/storage v1.55.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
304304
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
305305
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
306306
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
307-
github.com/containers/image/v5 v5.32.1 h1:fVa7GxRC4BCPGsfSRs4JY12WyeY26SUYQ0NuANaCFrI=
308-
github.com/containers/image/v5 v5.32.1/go.mod h1:v1l73VeMugfj/QtKI+jhYbwnwFCFnNGckvbST3rQ5Hk=
307+
github.com/containers/image/v5 v5.32.2 h1:SzNE2Y6sf9b1GJoC8qjCuMBXwQrACFp4p0RK15+4gmQ=
308+
github.com/containers/image/v5 v5.32.2/go.mod h1:v1l73VeMugfj/QtKI+jhYbwnwFCFnNGckvbST3rQ5Hk=
309309
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 h1:Qzk5C6cYglewc+UyGf6lc8Mj2UaPTHy/iF2De0/77CA=
310310
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01/go.mod h1:9rfv8iPl1ZP7aqh9YA68wnZv2NUDbXdcdPHVz0pFbPY=
311311
github.com/containers/ocicrypt v1.2.0 h1:X14EgRK3xNFvJEfI5O4Qn4T3E25ANudSOZz/sirVuPM=

scripts/registry_auth/htpasswd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test:$2y$05$0tIR2sbcMk3o4JtdIxrpEu79xyTeT/P6adlq6FcZF3IebVXb9Tat.
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kcl mod add helloworld --tag 0.1.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid flag '0.1.1' for oci registry ref, try 'kcl mod add helloworld:0.1.1'

test/e2e/test_suites/test_add_oci_ref_invalid/stdout

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "test_space"
3+
edition = "v0.9.0"
4+
version = "0.0.1"
5+
6+

test/e2e/test_suites/test_add_oci_ref_invalid/test_space/kcl.mod.lock

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The_first_kcl_program = 'Hello World!'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kcl mod add helloworld --commit invalidcommit
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid flag 'invalidcommit' for oci registry ref

test/e2e/test_suites/test_add_oci_ref_invalid_1/stdout

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "test_space"
3+
edition = "v0.9.0"
4+
version = "0.0.1"
5+
6+

test/e2e/test_suites/test_add_oci_ref_invalid_1/test_space/kcl.mod.lock

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The_first_kcl_program = 'Hello World!'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kcl mod add helloworld --branch invalidbranch
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invalid flag 'invalidbranch' for oci registry ref

test/e2e/test_suites/test_add_oci_ref_invalid_2/stdout

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "test_space"
3+
edition = "v0.9.0"
4+
version = "0.0.1"
5+
6+

test/e2e/test_suites/test_add_oci_ref_invalid_2/test_space/kcl.mod.lock

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The_first_kcl_program = 'Hello World!'

0 commit comments

Comments
 (0)