forked from kcl-lang/kpm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kcl-lang#63 from zong-zhe/add-kpm-pull
Feat: add 'kpm pull' to pull the kcl package from oci registry.
- Loading branch information
Showing
19 changed files
with
122 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2023 The KCL Authors. All rights reserved. | ||
|
||
package cmd | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/urfave/cli/v2" | ||
"kusionstack.io/kpm/pkg/oci" | ||
"kusionstack.io/kpm/pkg/opt" | ||
"kusionstack.io/kpm/pkg/reporter" | ||
"kusionstack.io/kpm/pkg/settings" | ||
) | ||
|
||
// NewPullCmd new a Command for `kpm pull`. | ||
func NewPullCmd(settings *settings.Settings) *cli.Command { | ||
return &cli.Command{ | ||
Hidden: false, | ||
Name: "pull", | ||
Usage: "pull kcl package from OCI registry.", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: FLAG_TAG, | ||
Usage: "the tag for oci artifact", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
tag := c.String(FLAG_TAG) | ||
ociUrl := c.Args().Get(0) | ||
localPath := c.Args().Get(1) | ||
|
||
if len(ociUrl) == 0 { | ||
reporter.Report("kpm: oci url must be specified.") | ||
reporter.ExitWithReport("kpm: run 'kpm pull help' for more information.") | ||
} | ||
|
||
ociOpt, err := opt.ParseOciOptionFromOciUrl(ociUrl, tag) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
absPullPath, err := filepath.Abs(localPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = oci.Pull(absPullPath, ociOpt.Reg, ociOpt.Repo, ociOpt.Tag, settings) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
reporter.Report("kpm: the kcl package tar is pulled successfully.") | ||
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
2 changes: 2 additions & 0 deletions
2
test/e2e/test_suites/kpm/no_args/kpm_pull_with_no_args/test_suite.env
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,2 @@ | ||
KPM_HOME="" | ||
KCLVM_VENDOR_HOME="" |
1 change: 1 addition & 0 deletions
1
test/e2e/test_suites/kpm/no_args/kpm_pull_with_no_args/test_suite.input
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 @@ | ||
kpm pull |
2 changes: 2 additions & 0 deletions
2
test/e2e/test_suites/kpm/no_args/kpm_pull_with_no_args/test_suite.stderr
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,2 @@ | ||
kpm: oci url must be specified. | ||
kpm: run 'kpm pull help' for more information. |
Empty file.
2 changes: 2 additions & 0 deletions
2
test/e2e/test_suites/kpm/no_args/kpm_pull_with_no_tag_arg/test_suite.env
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,2 @@ | ||
KPM_HOME="" | ||
KCLVM_VENDOR_HOME="" |
1 change: 1 addition & 0 deletions
1
test/e2e/test_suites/kpm/no_args/kpm_pull_with_no_tag_arg/test_suite.input
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 @@ | ||
kpm pull --tag |
1 change: 1 addition & 0 deletions
1
test/e2e/test_suites/kpm/no_args/kpm_pull_with_no_tag_arg/test_suite.stderr
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 @@ | ||
flag needs an argument: -tag |
14 changes: 14 additions & 0 deletions
14
test/e2e/test_suites/kpm/no_args/kpm_pull_with_no_tag_arg/test_suite.stdout
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,14 @@ | ||
Incorrect Usage: flag needs an argument: -tag | ||
|
||
NAME: | ||
kpm pull - pull kcl package from OCI registry. | ||
|
||
USAGE: | ||
kpm pull command [command options] [arguments...] | ||
|
||
COMMANDS: | ||
help, h Shows a list of commands or help for one command | ||
|
||
OPTIONS: | ||
--tag value the tag for oci artifact | ||
--help, -h show help |
2 changes: 2 additions & 0 deletions
2
test/e2e/test_suites/kpm/no_args/kpm_pull_with_only_tag/test_suite.env
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,2 @@ | ||
KPM_HOME="" | ||
KCLVM_VENDOR_HOME="" |
1 change: 1 addition & 0 deletions
1
test/e2e/test_suites/kpm/no_args/kpm_pull_with_only_tag/test_suite.input
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 @@ | ||
kpm pull --tag v0.0.1 |
2 changes: 2 additions & 0 deletions
2
test/e2e/test_suites/kpm/no_args/kpm_pull_with_only_tag/test_suite.stderr
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,2 @@ | ||
kpm: oci url must be specified. | ||
kpm: run 'kpm pull help' for more information. |
Empty file.
2 changes: 1 addition & 1 deletion
2
test/e2e/test_suites/kpm/no_args/login_reg_without_args/test_suite.stdout
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 |
---|---|---|
@@ -1 +1 @@ | ||
Username: | ||
Username: |
2 changes: 1 addition & 1 deletion
2
test/e2e/test_suites/kpm/no_args/login_reg_without_password/test_suite.stdout
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 |
---|---|---|
@@ -1 +1 @@ | ||
Password: | ||
Password: |