-
Notifications
You must be signed in to change notification settings - Fork 14
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 #103 from zong-zhe/unify-pull-cli
feat: unify pull cli
- Loading branch information
Showing
21 changed files
with
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,104 @@ | ||
package cmd | ||
|
||
import ( | ||
"net/url" | ||
|
||
"kcl-lang.io/kpm/pkg/client" | ||
"kcl-lang.io/kpm/pkg/constants" | ||
"kcl-lang.io/kpm/pkg/opt" | ||
) | ||
|
||
func argsGet(a []string, n int) string { | ||
if len(a) > n { | ||
return a[n] | ||
} | ||
return "" | ||
} | ||
|
||
func ParseUrlFromArgs(cli *client.KpmClient, args []string) (*url.URL, error) { | ||
var sourceUrl url.URL | ||
|
||
if len(args) == 0 { | ||
if len(git) != 0 { | ||
gitUrl, err := url.Parse(git) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
gitUrl.Scheme = constants.GitScheme | ||
query := gitUrl.Query() | ||
if tag != "" { | ||
query.Add(constants.Tag, tag) | ||
} | ||
if commit != "" { | ||
query.Add(constants.GitCommit, commit) | ||
} | ||
if branch != "" { | ||
query.Add(constants.GitBranch, branch) | ||
} | ||
gitUrl.RawQuery = query.Encode() | ||
sourceUrl = *gitUrl | ||
} else if len(oci) != 0 { | ||
ociUrl, err := url.Parse(oci) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ociUrl.Scheme = constants.OciScheme | ||
query := ociUrl.Query() | ||
query.Add(constants.Tag, tag) | ||
ociUrl.RawQuery = query.Encode() | ||
sourceUrl = *ociUrl | ||
} | ||
} else { | ||
url, err := url.Parse(args[0]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
query := url.Query() | ||
url.Opaque = "" | ||
regOpts, err := opt.NewRegistryOptionsFrom(args[0], cli.GetSettings()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if regOpts.Git != nil { | ||
if url.Scheme != constants.GitScheme && url.Scheme != constants.SshScheme { | ||
url.Scheme = constants.GitScheme | ||
} | ||
if tag != "" { | ||
query.Add(constants.Tag, tag) | ||
} | ||
if commit != "" { | ||
query.Add(constants.GitCommit, commit) | ||
} | ||
if branch != "" { | ||
query.Add(constants.GitBranch, branch) | ||
} | ||
} else if regOpts.Oci != nil { | ||
url.Scheme = constants.OciScheme | ||
url.Host = regOpts.Oci.Reg | ||
url.Path = regOpts.Oci.Repo | ||
if regOpts.Oci.Tag != "" { | ||
query.Add(constants.Tag, regOpts.Oci.Tag) | ||
} | ||
if tag != "" { | ||
query.Add(constants.Tag, tag) | ||
} | ||
} else if regOpts.Registry != nil { | ||
url.Scheme = constants.DefaultOciScheme | ||
url.Host = regOpts.Registry.Reg | ||
url.Path = regOpts.Registry.Repo | ||
if regOpts.Registry.Tag != "" { | ||
query.Add(constants.Tag, regOpts.Registry.Tag) | ||
} | ||
if tag != "" { | ||
query.Add(constants.Tag, tag) | ||
} | ||
} | ||
|
||
url.RawQuery = query.Encode() | ||
sourceUrl = *url | ||
} | ||
return &sourceUrl, 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
start to pull 'helloworld' | ||
the lastest version '0.1.1' will be pulled | ||
pulling 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld' | ||
pulled 'helloworld' in '<workspace>/test_space/localhost:5001/test/helloworld' successfully | ||
start to pull oci://localhost:5001/test/helloworld | ||
the lastest version '0.1.1' will be downloaded | ||
downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1' | ||
pulled helloworld 0.1.1 successfully |
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,3 +1,3 @@ | ||
start to pull 'helloworld:0.1.1' | ||
pulling 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld' | ||
pulled 'helloworld:0.1.1' in '<workspace>/test_space/localhost:5001/test/helloworld/0.1.1' successfully | ||
start to pull oci://localhost:5001/test/helloworld?tag=0.1.1 | ||
downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1' | ||
pulled helloworld 0.1.1 successfully |
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 @@ | ||
kcl mod pull oci://localhost:5001/test/helloworld:0.1.1 | ||
kcl mod pull oci://localhost:5001/test/helloworld --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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
start to pull 'oci://localhost:5001/test/helloworld:0.1.1' | ||
the lastest version '0.1.1' will be pulled | ||
pulling '/test/helloworld:0.1.1:0.1.1' from 'localhost:5001/test/helloworld:0.1.1' | ||
pulled 'oci://localhost:5001/test/helloworld:0.1.1' in '<workspace>/test_space/localhost:5001/test/helloworld:0.1.1' successfully | ||
start to pull oci://localhost:5001/test/helloworld?tag=0.1.1 | ||
downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1' | ||
pulled helloworld 0.1.1 successfully |
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 @@ | ||
kcl mod pull git://github.com/kcl-lang/flask-demo-kcl-manifests --commit ade147b |
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,3 @@ | ||
start to pull https://github.com/kcl-lang/flask-demo-kcl-manifests?commit=ade147b | ||
cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests' with commit 'ade147b' | ||
pulled flask_manifests 0.0.1 successfully |
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 @@ | ||
kcl mod pull --git https://github.com/kcl-lang/flask-demo-kcl-manifests --branch main |
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,3 @@ | ||
start to pull https://github.com/kcl-lang/flask-demo-kcl-manifests?branch=main | ||
cloning 'https://github.com/kcl-lang/flask-demo-kcl-manifests' | ||
pulled flask_manifests 0.0.1 successfully |
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 @@ | ||
kcl mod pull --oci http://localhost:5001/test/helloworld --tag 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,3 @@ | ||
start to pull oci://localhost:5001/test/helloworld?tag=0.1.1 | ||
downloading 'test/helloworld:0.1.1' from 'localhost:5001/test/helloworld:0.1.1' | ||
pulled helloworld 0.1.1 successfully |