Skip to content

Commit 8402460

Browse files
authored
Merge pull request #164 from kcl-lang/add-mod-spec
feat: make 'kcl mod add' supports ModSpec
2 parents 20d46fa + 7308b2c commit 8402460

File tree

52 files changed

+135
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+135
-42
lines changed

cmd/kcl/commands/mod_add.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ const (
4242
# Add the sub module dependency named "helloworld" from the Git repo by the tag flag with ssh url
4343
kcl mod add helloworld --git ssh://github.com/kcl-lang/modules --tag v0.1.0
4444
45+
# Add the sub module dependency named "cc" with version "0.0.1" from the Git repo by the commit flag with ssh url
46+
kcl mod add cc:0.0.1 --git https://github.com/kcl-lang/flask-demo-kcl-manifests --commit 8308200
47+
4548
# Add the module dependency from the OCI registry named "" by the tag flag
46-
kcl mod add --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.0`
49+
kcl mod add --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.0
50+
51+
# Add the sub module dependency named "subhelloworld" from the OCI registry by the tag flag
52+
kcl mod add subhelloworld --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.4
53+
54+
# Add the sub module dependency named "subhelloworld" with version "0.0.1" from the OCI registry by the tag flag
55+
kcl mod add subhelloworld:0.0.1 --oci https://ghcr.io/kcl-lang/helloworld --tag 0.1.4`
4756
)
4857

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

103-
kclPkg, err := pkg.LoadKclPkg(pwd)
112+
kclPkg, err := pkg.LoadKclPkgWithOpts(
113+
pkg.WithPath(pwd),
114+
pkg.WithSettings(cli.GetSettings()),
115+
)
104116
if err != nil {
105117
return err
106118
}
@@ -110,13 +122,13 @@ func ModAdd(cli *client.KpmClient, args []string) error {
110122
return err
111123
}
112124

113-
addOpts, err := parseAddOptions(cli, globalPkgPath, args)
125+
source, err := ParseSourceFromArgs(cli, args)
114126
if err != nil {
115127
return err
116128
}
117129

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

131-
err = addOpts.Validate()
132-
if err != nil {
133-
return err
134-
}
135-
136-
_, err = cli.AddDepWithOpts(kclPkg, addOpts)
143+
err = cli.Add(
144+
client.WithAddKclPkg(kclPkg),
145+
client.WithAddSource(source),
146+
)
137147
if err != nil {
138148
return err
139149
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
kcl-lang.io/kcl-go v0.10.8
1414
kcl-lang.io/kcl-openapi v0.10.0
1515
kcl-lang.io/kcl-plugin v0.6.0
16-
kcl-lang.io/kpm v0.10.1-0.20241107094147-b05e196b2c05
16+
kcl-lang.io/kpm v0.10.1-0.20241108070633-70859aba1f5b
1717
)
1818

1919
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,8 +1702,8 @@ kcl-lang.io/kcl-openapi v0.10.0 h1:yetZMSnn/HHaMcfiLt1P2zhCF06O33jxkjtHrm08VR8=
17021702
kcl-lang.io/kcl-openapi v0.10.0/go.mod h1:kGCf0AZygrZyB+xpmMtiC3FYoiV/1rCLXuAq2QtuLf8=
17031703
kcl-lang.io/kcl-plugin v0.6.0 h1:rBdoqKDPdOtojeOHCFnXoB/I7ltFjV61r0KkfOcL5sE=
17041704
kcl-lang.io/kcl-plugin v0.6.0/go.mod h1:LoIouleHYRKAvFcdW30yUlhsMYH2W9zD5Ji1XHfbht4=
1705-
kcl-lang.io/kpm v0.10.1-0.20241107094147-b05e196b2c05 h1:J+Leim2cR1h6KQ0DhurhrrctgVnLrhCC/wsgJWhcBw8=
1706-
kcl-lang.io/kpm v0.10.1-0.20241107094147-b05e196b2c05/go.mod h1:1ndoNvUQdYNgoiQHIkGGRUQIWLU8BSslIbJhk9B5Kco=
1705+
kcl-lang.io/kpm v0.10.1-0.20241108070633-70859aba1f5b h1:vpmjZzeTg9LSZwuk5MajFAMxBoOeLktVgdIRUydq/mc=
1706+
kcl-lang.io/kpm v0.10.1-0.20241108070633-70859aba1f5b/go.mod h1:1ndoNvUQdYNgoiQHIkGGRUQIWLU8BSslIbJhk9B5Kco=
17071707
kcl-lang.io/lib v0.10.8 h1:/Mhko6fngIstvdx9dAS3H6N1utogkWfoARVj643l5nU=
17081708
kcl-lang.io/lib v0.10.8/go.mod h1:0Dw/MQwRMjLDksxl4JerGBn/ueaxRyCCKBCCwQwJ1MI=
17091709
oras.land/oras-go v1.2.6 h1:z8cmxQXBU8yZ4mkytWqXfo6tZcamPwjsuxYU81xJ8Lk=

scripts/e2e/pull_pkg.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ if [ ! -d "./oci/ghcr.io/kcl-lang/helloworld/0.1.1/helloworld/0.1.1" ]; then
2525
$current_dir/bin/kcl mod pull helloworld:0.1.1
2626
fi
2727

28+
if [ ! -d "./oci/ghcr.io/kcl-lang/helloworld/0.1.4/helloworld/0.1.4" ]; then
29+
$current_dir/bin/kcl mod pull helloworld:0.1.4
30+
fi
31+
2832
cd "$current_dir"

scripts/e2e/push_pkg.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ $current_dir/bin/kcl mod push
2727

2828
cd "$current_dir"
2929

30+
# Push the package helloworld/0.1.4 to the registry
31+
cd ./scripts/e2e/pkg_in_reg/oci/ghcr.io/kcl-lang/helloworld/0.1.4/helloworld/0.1.4
32+
$current_dir/bin/kcl mod push
33+
34+
cd "$current_dir"
35+
3036
# Push the package 'kcl1' depends on 'k8s' to the registry
3137
cd ./scripts/e2e/pkg_in_reg/kcl1
3238
$current_dir/bin/kcl mod push
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add dependency 'helloworld:0.1.1' successfully
1+
add dependency 'helloworld:0.1.4' successfully
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add dependency 'konfig:v0.4.0' successfully
1+
add dependency 'konfig:0.3.0' successfully
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add dependency 'konfig:main' successfully
1+
add dependency 'konfig:0.13.0' successfully
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add dependency 'konfig:01ca24c' successfully
1+
add dependency 'konfig:0.4.0' successfully
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
add dependency 'konfig:01ca24c' successfully
1+
add dependency 'konfig:0.4.0' successfully

0 commit comments

Comments
 (0)