-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmod_update.go
74 lines (62 loc) · 1.42 KB
/
mod_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package cmd
import (
"os"
"github.com/spf13/cobra"
"kcl-lang.io/kpm/pkg/client"
"kcl-lang.io/kpm/pkg/env"
"kcl-lang.io/kpm/pkg/errors"
"kcl-lang.io/kpm/pkg/reporter"
)
const (
modUpdateDesc = `This command updates dependencies listed in kcl.mod.lock based on kcl.mod.
`
modUpdateExample = ` # Update the current module
kcl mod update
# Update the module with the specified path
kcl mod update path/to/package`
)
// NewModUpdateCmd returns the mod update command.
func NewModUpdateCmd(cli *client.KpmClient) *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Short: "updates dependencies",
Long: modUpdateDesc,
Example: modUpdateExample,
RunE: func(_ *cobra.Command, args []string) error {
return ModUpdate(cli, args)
},
SilenceUsage: true,
}
return cmd
}
func ModUpdate(cli *client.KpmClient, args []string) error {
pkgPath := argsGet(args, 0)
if len(pkgPath) == 0 {
pwd, err := os.Getwd()
if err != nil {
return errors.InternalBug
}
pkgPath = pwd
}
kclPkg, err := cli.LoadPkgFromPath(pkgPath)
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 = cli.ResolveDepsMetadataInJsonStr(kclPkg, true)
if err != nil {
return err
}
err = kclPkg.UpdateModAndLockFile()
if err != nil {
return err
}
return nil
}