Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make 'kcl mod add' supports ModSpec #164

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions cmd/kcl/commands/mod_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ const (
# Add the sub module dependency named "helloworld" from the Git repo by the tag flag with ssh url
kcl mod add helloworld --git ssh://github.com/kcl-lang/modules --tag v0.1.0

# Add the sub module dependency named "cc" with version "0.0.1" from the Git repo by the commit flag with ssh url
kcl mod add cc:0.0.1 --git https://github.com/kcl-lang/flask-demo-kcl-manifests --commit 8308200

# Add the module dependency from the OCI registry named "" by the tag flag
kcl mod add --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.0`
kcl mod add --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.0

# Add the sub module dependency named "subhelloworld" from the OCI registry by the tag flag
kcl mod add subhelloworld --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.4

# Add the sub module dependency named "subhelloworld" with version "0.0.1" from the OCI registry by the tag flag
kcl mod add subhelloworld:0.0.1 --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.4`
)

// NewModAddCmd returns the mod add command.
Expand Down Expand Up @@ -100,7 +109,10 @@ func ModAdd(cli *client.KpmClient, args []string) error {
return err
}

kclPkg, err := pkg.LoadKclPkg(pwd)
kclPkg, err := pkg.LoadKclPkgWithOpts(
pkg.WithPath(pwd),
pkg.WithSettings(cli.GetSettings()),
)
if err != nil {
return err
}
Expand All @@ -110,13 +122,13 @@ func ModAdd(cli *client.KpmClient, args []string) error {
return err
}

addOpts, err := parseAddOptions(cli, globalPkgPath, args)
source, err := ParseSourceFromArgs(cli, args)
if err != nil {
return err
}

if addOpts.RegistryOpts.Local != nil {
absAddPath, err := filepath.Abs(addOpts.RegistryOpts.Local.Path)
if source.Local != nil {
absAddPath, err := filepath.Abs(source.Local.Path)
if err != nil {
return reporter.NewErrorEvent(reporter.Bug, err, "internal bugs, please contact us to fix it.")
}
Expand All @@ -128,12 +140,10 @@ func ModAdd(cli *client.KpmClient, args []string) error {
}
}

err = addOpts.Validate()
if err != nil {
return err
}

_, err = cli.AddDepWithOpts(kclPkg, addOpts)
err = cli.Add(
client.WithAddKclPkg(kclPkg),
client.WithAddSource(source),
)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
kcl-lang.io/kcl-go v0.10.8
kcl-lang.io/kcl-openapi v0.10.0
kcl-lang.io/kcl-plugin v0.6.0
kcl-lang.io/kpm v0.10.1-0.20241107094147-b05e196b2c05
kcl-lang.io/kpm v0.10.1-0.20241108034557-9be57610ec73
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,8 @@ kcl-lang.io/kcl-openapi v0.10.0 h1:yetZMSnn/HHaMcfiLt1P2zhCF06O33jxkjtHrm08VR8=
kcl-lang.io/kcl-openapi v0.10.0/go.mod h1:kGCf0AZygrZyB+xpmMtiC3FYoiV/1rCLXuAq2QtuLf8=
kcl-lang.io/kcl-plugin v0.6.0 h1:rBdoqKDPdOtojeOHCFnXoB/I7ltFjV61r0KkfOcL5sE=
kcl-lang.io/kcl-plugin v0.6.0/go.mod h1:LoIouleHYRKAvFcdW30yUlhsMYH2W9zD5Ji1XHfbht4=
kcl-lang.io/kpm v0.10.1-0.20241107094147-b05e196b2c05 h1:J+Leim2cR1h6KQ0DhurhrrctgVnLrhCC/wsgJWhcBw8=
kcl-lang.io/kpm v0.10.1-0.20241107094147-b05e196b2c05/go.mod h1:1ndoNvUQdYNgoiQHIkGGRUQIWLU8BSslIbJhk9B5Kco=
kcl-lang.io/kpm v0.10.1-0.20241108034557-9be57610ec73 h1:eJ30UC0O/kEDPVJgfAcfpzmYCYfO5mWyGD4uPs6hc28=
kcl-lang.io/kpm v0.10.1-0.20241108034557-9be57610ec73/go.mod h1:1ndoNvUQdYNgoiQHIkGGRUQIWLU8BSslIbJhk9B5Kco=
kcl-lang.io/lib v0.10.8 h1:/Mhko6fngIstvdx9dAS3H6N1utogkWfoARVj643l5nU=
kcl-lang.io/lib v0.10.8/go.mod h1:0Dw/MQwRMjLDksxl4JerGBn/ueaxRyCCKBCCwQwJ1MI=
oras.land/oras-go v1.2.6 h1:z8cmxQXBU8yZ4mkytWqXfo6tZcamPwjsuxYU81xJ8Lk=
Expand Down
4 changes: 4 additions & 0 deletions scripts/e2e/pull_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ if [ ! -d "./oci/ghcr.io/kcl-lang/helloworld/0.1.1/helloworld/0.1.1" ]; then
$current_dir/bin/kcl mod pull helloworld:0.1.1
fi

if [ ! -d "./oci/ghcr.io/kcl-lang/helloworld/0.1.4/helloworld/0.1.4" ]; then
$current_dir/bin/kcl mod pull helloworld:0.1.4
fi

cd "$current_dir"
6 changes: 6 additions & 0 deletions scripts/e2e/push_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ $current_dir/bin/kcl mod push

cd "$current_dir"

# Push the package helloworld/0.1.4 to the registry
cd ./scripts/e2e/pkg_in_reg/oci/ghcr.io/kcl-lang/helloworld/0.1.4/helloworld/0.1.4
$current_dir/bin/kcl mod push

cd "$current_dir"

# Push the package 'kcl1' depends on 'k8s' to the registry
cd ./scripts/e2e/pkg_in_reg/kcl1
$current_dir/bin/kcl mod push
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_add_oci_ref_tag/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'helloworld:0.1.1' successfully
add dependency 'helloworld:0.1.4' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'konfig:v0.4.0' successfully
add dependency 'konfig:0.3.0' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_1/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'konfig:main' successfully
add dependency 'konfig:0.13.0' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_2/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'konfig:01ca24c' successfully
add dependency 'konfig:0.4.0' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_3/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'konfig:01ca24c' successfully
add dependency 'konfig:0.4.0' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_4/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'konfig:main' successfully
add dependency 'konfig:0.13.0' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_5/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'konfig:main' successfully
add dependency 'konfig:0.13.0' successfully
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_kcl_mod_add_git_modspec/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl mod add cc --git https://github.com/kcl-lang/flask-demo-kcl-manifests --commit 8308200
Empty file.
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_kcl_mod_add_git_modspec/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add dependency 'cc:0.0.1' successfully
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_space"
edition = "v0.10.0"
version = "0.0.1"

[dependencies]
cc = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "8308200", version = "0.0.1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[dependencies]
[dependencies.cc]
name = "cc"
full_name = "cc_0.0.1"
version = "0.0.1"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests"
commit = "8308200"
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_kcl_mod_add_git_modspec_0/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl mod add cc:0.0.1 --git https://github.com/kcl-lang/flask-demo-kcl-manifests --commit 8308200
Empty file.
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_kcl_mod_add_git_modspec_0/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add dependency 'cc:0.0.1' successfully
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_space"
edition = "v0.10.0"
version = "0.0.1"

[dependencies]
cc = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "8308200", version = "0.0.1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[dependencies]
[dependencies.cc]
name = "cc"
full_name = "cc_0.0.1"
version = "0.0.1"
url = "https://github.com/kcl-lang/flask-demo-kcl-manifests"
commit = "8308200"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_url/input
Original file line number Diff line number Diff line change
@@ -1 +1 @@
kcl mod add https://github.com/kcl-lang/flask-demo-kcl-manifests.git --commit ade147b
kcl mod add git://github.com/kcl-lang/flask-demo-kcl-manifests.git --commit ade147b
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_url/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'flask-demo-kcl-manifests:ade147b' successfully
add dependency 'flask_manifests:0.0.1' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_url_1/input
Original file line number Diff line number Diff line change
@@ -1 +1 @@
kcl mod add https://github.com/kcl-lang/flask-demo-kcl-manifests.git --branch main
kcl mod add git://github.com/kcl-lang/flask-demo-kcl-manifests.git --branch main
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_url_1/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'flask-demo-kcl-manifests:main' successfully
add dependency 'flask_manifests:0.0.1' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_url_2/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'flask-demo-kcl-manifests:main' successfully
add dependency 'flask_manifests:0.0.1' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_url_3/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'flask-demo-kcl-manifests:ade147b' successfully
add dependency 'flask_manifests:0.0.1' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_git_url_4/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'flask-demo-kcl-manifests:ade147b' successfully
add dependency 'flask_manifests:0.0.1' successfully
3 changes: 1 addition & 2 deletions test/e2e/test_suites/test_kcl_mod_add_local_0/stdout
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
adding dependency 'dep'
add dependency 'dep:0.0.1' successfully
add dependency 'dep:0.0.1' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_oci/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'helloworld' successfully
add dependency 'helloworld:0.1.4' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_oci_1/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'kcl1' successfully
add dependency 'kcl1:0.0.1' successfully
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_kcl_mod_add_oci_modspec/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl mod add subhelloworld --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.4
Empty file.
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_kcl_mod_add_oci_modspec/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add dependency 'subhelloworld:0.0.1' successfully
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_space"
edition = "v0.10.0"
version = "0.0.1"

[dependencies]
subhelloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.4", version = "0.0.1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[dependencies]
[dependencies.subhelloworld]
name = "subhelloworld"
full_name = "subhelloworld_0.0.1"
version = "0.0.1"
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
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_kcl_mod_add_oci_modspec_0/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kcl mod add subhelloworld:0.0.1 --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.4
Empty file.
1 change: 1 addition & 0 deletions test/e2e/test_suites/test_kcl_mod_add_oci_modspec_0/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add dependency 'subhelloworld:0.0.1' successfully
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "test_space"
edition = "v0.10.0"
version = "0.0.1"

[dependencies]
subhelloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.4", version = "0.0.1" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[dependencies]
[dependencies.subhelloworld]
name = "subhelloworld"
full_name = "subhelloworld_0.0.1"
version = "0.0.1"
reg = "ghcr.io"
repo = "kcl-lang/helloworld"
oci_tag = "0.1.4"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_oci_url/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'helloworld' successfully
add dependency 'helloworld:0.1.4' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_oci_url_2/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'helloworld' successfully
add dependency 'helloworld:0.1.4' successfully
2 changes: 1 addition & 1 deletion test/e2e/test_suites/test_kcl_mod_add_oci_url_4/stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add dependency 'helloworld' successfully
add dependency 'helloworld:0.1.4' successfully
6 changes: 3 additions & 3 deletions test/e2e/test_suites/test_kcl_mod_pull/stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
start to pull oci://localhost:5001/test/helloworld
the lastest version '0.1.1' will be downloaded
downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1'
pulled helloworld 0.1.1 successfully
the lastest version '0.1.4' will be downloaded
downloading 'test/helloworld:0.1.4' from 'localhost:5001/test/helloworld:0.1.4'
pulled helloworld 0.1.4 successfully
6 changes: 4 additions & 2 deletions test/e2e/test_suites/test_kcl_run_11/stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
the lastest version '0.1.1' will be downloaded
downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1'
the lastest version '0.1.4' will be downloaded
downloading 'test/helloworld:0.1.4' from 'localhost:5001/test/helloworld:0.1.4'
The_fisrt_schema_inst:
msg: Hello Schema!
The_first_kcl_program: Hello World!
6 changes: 4 additions & 2 deletions test/e2e/test_suites/test_kcl_run_2/stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
the lastest version '0.1.1' will be downloaded
downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1'
the lastest version '0.1.4' will be downloaded
downloading 'test/helloworld:0.1.4' from 'localhost:5001/test/helloworld:0.1.4'
The_fisrt_schema_inst:
msg: Hello Schema!
The_first_kcl_program: Hello World!
Loading