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

added rename flag in kpm add #318

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,17 @@ func (c *KpmClient) AddDepWithOpts(kclPkg *pkg.KclPkg, opt *opt.AddOptions) (*pk
fmt.Sprintf("adding dependency '%s'", d.Name),
c.logWriter,
)

// 2. download the dependency to the local path.
err = c.AddDepToPkg(kclPkg, d)
if err != nil {
return nil, err
}

// 3. update the kcl.mod and kcl.mod.lock.
if opt.NewPkgName != "" {
d.ChangePkgName(opt.NewPkgName)
}
err = kclPkg.UpdateModAndLockFile()
if err != nil {
return nil, err
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/cmd_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func NewAddCmd(kpmcli *client.KpmClient) *cli.Command {
Name: FLAG_NO_SUM_CHECK,
Usage: "do not check the checksum of the package and update kcl.mod.lock",
},
&cli.StringFlag{
Name: "rename",
Usage: "rename the package name in kcl.mod.lock",
},
},

Action: func(c *cli.Context) error {
Expand Down Expand Up @@ -131,6 +135,7 @@ func onlyOnceOption(c *cli.Context, name string) (string, *reporter.KpmEvent) {
// parseAddOptions will parse the user cli inputs.
func parseAddOptions(c *cli.Context, kpmcli *client.KpmClient, localPath string) (*opt.AddOptions, error) {
noSumCheck := c.Bool(FLAG_NO_SUM_CHECK)
newPkgName := c.String("rename")
// parse from 'kpm add -git https://xxx/xxx.git -tag v0.0.1'.
if c.NArg() == 0 {
gitOpts, err := parseGitRegistryOptions(c)
Expand All @@ -142,6 +147,7 @@ func parseAddOptions(c *cli.Context, kpmcli *client.KpmClient, localPath string)
}
return &opt.AddOptions{
LocalPath: localPath,
NewPkgName: newPkgName,
RegistryOpts: *gitOpts,
NoSumCheck: noSumCheck,
}, nil
Expand All @@ -155,12 +161,14 @@ func parseAddOptions(c *cli.Context, kpmcli *client.KpmClient, localPath string)
}
return &opt.AddOptions{
LocalPath: localPath,
NewPkgName: newPkgName,
RegistryOpts: *ociReg,
NoSumCheck: noSumCheck,
}, nil
} else {
return &opt.AddOptions{
LocalPath: localPath,
NewPkgName: newPkgName,
RegistryOpts: *localPkg,
NoSumCheck: noSumCheck,
}, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/opt/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (opts *InitOptions) Validate() error {

type AddOptions struct {
LocalPath string
NewPkgName string
RegistryOpts RegistryOptions
NoSumCheck bool
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/package/modfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func (dep *Dependency) GetDownloadPath() string {
return ""
}

func (dep *Dependency) ChangePkgName(NewPkgName string) {
dep.Name = NewPkgName
}

func GenSource(sourceType string, uri string, tagName string) (Source, error) {
source := Source{}
if sourceType == GIT {
Expand Down
Loading