-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 'kpm update' to update the dependencies
Signed-off-by: zongz <[email protected]>
- Loading branch information
Showing
22 changed files
with
264 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
pkg/client/test_data/test_update/test_update_kcl_mod/expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[dependencies] | ||
[dependencies.helloworld] | ||
name = "helloworld" | ||
full_name = "helloworld_0.1.1" | ||
version = "0.1.1" | ||
sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" | ||
reg = "ghcr.io" | ||
repo = "kcl-lang/helloworld" | ||
oci_tag = "0.1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "test_update" | ||
edition = "0.0.1" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
helloworld = "0.1.1" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
Empty file.
4 changes: 4 additions & 0 deletions
4
pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "test_update" | ||
edition = "0.0.1" | ||
version = "0.0.1" |
9 changes: 9 additions & 0 deletions
9
pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[dependencies] | ||
[dependencies.helloworld] | ||
name = "helloworld" | ||
full_name = "helloworld_0.1.1" | ||
version = "0.1.1" | ||
sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" | ||
reg = "ghcr.io" | ||
repo = "kcl-lang/helloworld" | ||
oci_tag = "0.1.1" |
1 change: 1 addition & 0 deletions
1
pkg/client/test_data/test_update/test_update_kcl_mod_lock/main.k
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 The KCL Authors. All rights reserved. | ||
|
||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
"kcl-lang.io/kpm/pkg/client" | ||
"kcl-lang.io/kpm/pkg/env" | ||
"kcl-lang.io/kpm/pkg/errors" | ||
pkg "kcl-lang.io/kpm/pkg/package" | ||
"kcl-lang.io/kpm/pkg/reporter" | ||
) | ||
|
||
// NewUpdateCmd new a Command for `kpm update`. | ||
func NewUpdateCmd(kpmcli *client.KpmClient) *cli.Command { | ||
return &cli.Command{ | ||
Hidden: false, | ||
Name: "update", | ||
Usage: "Update dependencies listed in kcl.mod.lock", | ||
Action: func(c *cli.Context) error { | ||
return KpmUpdate(c, kpmcli) | ||
}, | ||
} | ||
} | ||
|
||
func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error { | ||
input_paths := c.Args().Slice() | ||
|
||
pkg_paths := []string{} | ||
if len(input_paths) == 0 { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
return errors.InternalBug | ||
} | ||
pkg_paths = append(pkg_paths, pwd) | ||
} else { | ||
pkg_paths = input_paths | ||
} | ||
|
||
for _, pkg_path := range pkg_paths { | ||
kclPkg, err := pkg.LoadKclPkg(pkg_path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
globalPkgPath, err := env.GetAbsPkgPath() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = kclPkg.ValidateKpmHome(globalPkgPath) | ||
if err != (*reporter.KpmEvent)(nil) { | ||
return err | ||
} | ||
|
||
_, err = kpmcli.ResolveDepsMetadataInJsonStr(kclPkg, true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = kclPkg.UpdateModAndLockFile() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.