Skip to content

Commit

Permalink
fix: rm useless code changes
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe committed Nov 7, 2024
1 parent ed16b08 commit 118aab4
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 178 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/example-e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: example-e2e-tests
on: push
# pull_request:
# branches:
# - main
# push:
# branches:
# - main
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
ubuntu:
strategy:
Expand Down
164 changes: 64 additions & 100 deletions cmd/kcl/commands/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,123 +120,87 @@ func ParseSourceFromArgs(cli *client.KpmClient, args []string) (*downloader.Sour
func ParseUrlFromArgs(cli *client.KpmClient, args []string) (*url.URL, error) {
var sourceUrl url.URL

// Parse the source url from the args
if len(git) != 0 {
gitUrl, err := url.Parse(git)
if err != nil {
return nil, err
}
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 != "" {
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
}
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)
} else {
url, err := url.Parse(args[0])
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 if len(path) != 0 {
pathUrl, err := url.Parse(path)
query := url.Query()
url.Opaque = ""
regOpts, err := opt.NewRegistryOptionsFrom(args[0], cli.GetSettings())
if err != nil {
return nil, err
}
sourceUrl = *pathUrl
}

// Parse the mod spec from the args
if len(args) != 0 {
source, err := downloader.NewSourceFromStr(sourceUrl.String())
if err != nil {
return nil, err
}
source.ModSpec = &downloader.ModSpec{}
err = source.ModSpec.FromString(args[0])
if err != nil {
url, err := url.Parse(args[0])
if err != nil {
return nil, err
if regOpts.Git != nil {
if url.Scheme != constants.GitScheme && url.Scheme != constants.SshScheme {
url.Scheme = constants.GitScheme
}
query := url.Query()
url.Opaque = ""
regOpts, err := opt.NewRegistryOptionsFrom(args[0], cli.GetSettings())
if err != nil {
return nil, err
if tag != "" {
query.Add(constants.Tag, tag)
}

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)
}
if commit != "" {
query.Add(constants.GitCommit, commit)
}

url.RawQuery = query.Encode()
sourceUrl = *url
} else {
if source.SpecOnly() {
source.Oci = &downloader.Oci{
Reg: cli.GetSettings().DefaultOciRegistry(),
Repo: utils.JoinPath(cli.GetSettings().DefaultOciRepo(), source.ModSpec.Name),
Tag: source.ModSpec.Version,
}
if branch != "" {
query.Add(constants.GitBranch, branch)
}

urlStr, err := source.ToString()
if err != nil {
return nil, err
} 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)
}

urlWithSpec, err := url.Parse(urlStr)
if err != nil {
return nil, err
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)
}
sourceUrl = *urlWithSpec
}
}

url.RawQuery = query.Encode()
sourceUrl = *url
}
return &sourceUrl, nil
}
2 changes: 0 additions & 2 deletions cmd/kcl/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ func appendLangFlags(o *options.RunOptions, flags *pflag.FlagSet) {
"Specify the KCL module git url")
flags.StringVarP(&o.Oci, "oci", "", "",
"Specify the KCL module oci url")
flags.StringVarP(&o.Path, "path", "", "",
"Specify the KCL module local path")
flags.StringVarP(&o.Tag, "tag", "t", "",
"Specify the tag for the OCI or Git artifact")
flags.StringVarP(&o.Commit, "commit", "c", "",
Expand Down
2 changes: 1 addition & 1 deletion examples/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pwd=$(
pwd
)

for path in "configuration" "validation" "abstraction" "definition" "konfig" "mutation" "data-integration" "automation" "package-management" "kubernetes" "codelab" "server" "settings" "source" "run"; do
for path in "configuration" "validation" "abstraction" "definition" "konfig" "mutation" "data-integration" "automation" "package-management" "kubernetes" "codelab" "server" "settings" "source"; do
echo "\033[1mTesting $path ...\033[0m"
if (cd $pwd/$path && make test); then
echo "\033[32mTest SUCCESSED - $path\033[0m\n"
Expand Down
80 changes: 12 additions & 68 deletions pkg/options/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ import (
"kcl-lang.io/kcl-go/pkg/tools/gen"
"kcl-lang.io/kpm/pkg/client"
"kcl-lang.io/kpm/pkg/constants"
"kcl-lang.io/kpm/pkg/downloader"
"kcl-lang.io/kpm/pkg/opt"
pkg "kcl-lang.io/kpm/pkg/package"
"kcl-lang.io/kpm/pkg/runner"
"kcl-lang.io/kpm/pkg/settings"
"kcl-lang.io/kpm/pkg/utils"
)

const (
Expand Down Expand Up @@ -70,8 +67,6 @@ type RunOptions struct {
Git string
// Oci Url is the package url of the OCI artifact.
Oci string
// Path is the package path of the local artifact.
Path string
// Tag is the package tag of the OCI or Git artifact.
Tag string
// Commit is the package commit of the Git artifact.
Expand Down Expand Up @@ -162,7 +157,6 @@ func (o *RunOptions) Run() error {

// Complete completes the options based on the provided arguments.
func (o *RunOptions) Complete(args []string) error {
var pkgSourceUrl *url.URL = nil
if len(o.Git) != 0 {
gitUrl, err := url.Parse(o.Git)
if err != nil {
Expand All @@ -182,7 +176,7 @@ func (o *RunOptions) Complete(args []string) error {
query.Set("branch", o.Branch)
}
gitUrl.RawQuery = query.Encode()
pkgSourceUrl = gitUrl
o.Entries = append(o.Entries, gitUrl.String())
}

if len(o.Oci) != 0 {
Expand All @@ -198,76 +192,26 @@ func (o *RunOptions) Complete(args []string) error {
query.Set("tag", o.Tag)
}
ociUrl.RawQuery = query.Encode()
pkgSourceUrl = ociUrl
o.Entries = append(o.Entries, ociUrl.String())
}

if len(o.Path) != 0 {
pathUrl, err := url.Parse(o.Path)
if err != nil {
return err
}
pkgSourceUrl = pathUrl
}
modSpec := downloader.ModSpec{}
var err error
for _, arg := range args {
err = modSpec.FromString(arg)
if err != nil || utils.DirExists(arg) {
modSpec = downloader.ModSpec{}
argUrl, err := url.Parse(arg)
if err != nil {
return err
}
query := argUrl.Query()
if o.Tag != "" {
query.Set("tag", o.Tag)
}
if o.Commit != "" {
query.Set("commit", o.Commit)
}
if o.Branch != "" {
query.Set("branch", o.Branch)
}
argUrl.RawQuery = query.Encode()
if pkgSourceUrl != nil {
o.Entries = append(o.Entries, pkgSourceUrl.String())
}
pkgSourceUrl = argUrl
o.Entries = append(o.Entries, pkgSourceUrl.String())
pkgSourceUrl = nil
}
}

if !modSpec.IsNil() && err == nil {
source, err := downloader.NewSourceFromStr(pkgSourceUrl.String())
argUrl, err := url.Parse(arg)
if err != nil {
return err
}
source.ModSpec = &modSpec

if source.SpecOnly() {
source.Oci = &downloader.Oci{
Reg: settings.GetSettings().DefaultOciRegistry(),
Repo: utils.JoinPath(settings.GetSettings().DefaultOciRepo(), source.ModSpec.Name),
Tag: source.ModSpec.Version,
}
}

urlStr, err := source.ToString()
if err != nil {
return err
query := argUrl.Query()
if o.Tag != "" {
query.Set("tag", o.Tag)
}

urlWithSpec, err := url.Parse(urlStr)
if err != nil {
return err
if o.Commit != "" {
query.Set("commit", o.Commit)
}
if pkgSourceUrl.Scheme != "" {
urlWithSpec.Scheme = pkgSourceUrl.Scheme
if o.Branch != "" {
query.Set("branch", o.Branch)
}
o.Entries = append(o.Entries, urlWithSpec.String())
} else if pkgSourceUrl != nil {
o.Entries = append(o.Entries, pkgSourceUrl.String())
argUrl.RawQuery = query.Encode()
o.Entries = append(o.Entries, argUrl.String())
}
return nil
}
Expand Down

0 comments on commit 118aab4

Please sign in to comment.