Skip to content

Commit

Permalink
feat: add a diagnostic for the invalid flag when add oci ref
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <zongzhe1024@163.com>
  • Loading branch information
zong-zhe committed Aug 28, 2024
1 parent d174d9c commit 6abc8a2
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 3 deletions.
17 changes: 17 additions & 0 deletions cmd/kcl/commands/mod_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,23 @@ func parseAddOptions(cli *client.KpmClient, localPath string, args []string) (*o
regOpt.Git.Branch = branch
} else if regOpt.Oci != nil && len(tag) != 0 {
regOpt.Oci.Tag = tag
} else if regOpt.Registry != nil {
var invalidFlag string
if len(tag) != 0 {
invalidFlag = tag
} else if len(commit) != 0 {
invalidFlag = commit
} else if len(branch) != 0 {
invalidFlag = branch
}
var diagMsg string
if len(invalidFlag) != 0 {
diagMsg = fmt.Sprintf("invalid flag '%s' for oci registry ref", invalidFlag)
}
if len(tag) != 0 {
diagMsg = fmt.Sprintf("%s, try 'kcl mod add %s:%s'", diagMsg, pkgSource, tag)
}
return nil, fmt.Errorf(diagMsg)
}

return &opt.AddOptions{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/containerd/errdefs v0.1.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/containers/image/v5 v5.32.1 // indirect
github.com/containers/image/v5 v5.32.2 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.2.0 // indirect
github.com/containers/storage v1.55.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
github.com/containers/image/v5 v5.32.1 h1:fVa7GxRC4BCPGsfSRs4JY12WyeY26SUYQ0NuANaCFrI=
github.com/containers/image/v5 v5.32.1/go.mod h1:v1l73VeMugfj/QtKI+jhYbwnwFCFnNGckvbST3rQ5Hk=
github.com/containers/image/v5 v5.32.2 h1:SzNE2Y6sf9b1GJoC8qjCuMBXwQrACFp4p0RK15+4gmQ=
github.com/containers/image/v5 v5.32.2/go.mod h1:v1l73VeMugfj/QtKI+jhYbwnwFCFnNGckvbST3rQ5Hk=
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 h1:Qzk5C6cYglewc+UyGf6lc8Mj2UaPTHy/iF2De0/77CA=
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01/go.mod h1:9rfv8iPl1ZP7aqh9YA68wnZv2NUDbXdcdPHVz0pFbPY=
github.com/containers/ocicrypt v1.2.0 h1:X14EgRK3xNFvJEfI5O4Qn4T3E25ANudSOZz/sirVuPM=
Expand Down
2 changes: 2 additions & 0 deletions scripts/registry_auth/htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:$2y$05$0tIR2sbcMk3o4JtdIxrpEu79xyTeT/P6adlq6FcZF3IebVXb9Tat.

1 change: 1 addition & 0 deletions test/e2e/test_suites/test_add_oci_ref_invalid/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl mod add helloworld --tag 0.1.1
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_add_oci_ref_invalid/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid flag '0.1.1' for oci registry ref, try 'kcl mod add helloworld:0.1.1'
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "test_space"
edition = "v0.9.0"
version = "0.0.1"


Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_add_oci_ref_invalid_1/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl mod add helloworld --commit invalidcommit
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_add_oci_ref_invalid_1/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid flag 'invalidcommit' for oci registry ref
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "test_space"
edition = "v0.9.0"
version = "0.0.1"


Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_add_oci_ref_invalid_2/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl mod add helloworld --branch invalidbranch
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_add_oci_ref_invalid_2/stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid flag 'invalidbranch' for oci registry ref
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "test_space"
edition = "v0.9.0"
version = "0.0.1"


Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'

0 comments on commit 6abc8a2

Please sign in to comment.