Skip to content

Commit

Permalink
feat: take 'Workdir' as package path for api (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
zong-zhe authored Sep 13, 2023
1 parent ae90a2b commit cf53e94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/opt/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
type CompileOptions struct {
isVendor bool
hasSettingsYaml bool
pkgPath string
entries []string
*kcl.Option
}
Expand Down Expand Up @@ -67,12 +66,12 @@ func (opts *CompileOptions) IsVendor() bool {

// PkgPath will return the home path for a kcl package during compilation
func (opts *CompileOptions) PkgPath() string {
return opts.pkgPath
return opts.WorkDir
}

// SetPkgPath will set the home path for a kcl package during compilation
func (opts *CompileOptions) SetPkgPath(pkgPath string) {
opts.pkgPath = pkgPath
opts.Merge(kcl.WithWorkDir(pkgPath))
}

// Input options of 'kpm init'.
Expand Down
8 changes: 8 additions & 0 deletions pkg/opt/opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"kcl-lang.io/kcl-go/pkg/kcl"
)

func TestParseOciOptionFromString(t *testing.T) {
Expand Down Expand Up @@ -33,3 +34,10 @@ func TestParseOciOptionFromString(t *testing.T) {
assert.Equal(t, ociOption.Repo, "/test_oci_repo")
assert.Equal(t, ociOption.Tag, "test_tag")
}

func TestWorkDirAsPkgPath(t *testing.T) {
opts := DefaultCompileOptions()
assert.Equal(t, opts.PkgPath(), "")
opts.Merge(kcl.WithWorkDir("test_work_dir"))
assert.Equal(t, opts.PkgPath(), "test_work_dir")
}

0 comments on commit cf53e94

Please sign in to comment.