-
Notifications
You must be signed in to change notification settings - Fork 44
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
feat: add a api for unifying the KCL cli #369
Conversation
} | ||
} | ||
|
||
func (c *KpmClient) Add(options ...AddOption) (*pkg.KclPkg, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can split this to some small functions.
return "", fmt.Errorf("no kcl module root path found") | ||
} | ||
|
||
func (source *Source) ToFilePath() (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use some abstract interfaces or factory methods to implement redundant if else code, improving the level of abstraction while avoiding bugs.
|
||
type AddOption func(*AddOptions) error | ||
|
||
func WithNewPkgName(name string) AddOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more docs and examples for public APIs.
} | ||
} | ||
|
||
if runtime.GOOS != "windows" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest use a new function for this judgment, e.g.,
func moveTmpDirToLocal
|
||
type PullOption func(*PullOptions) error | ||
|
||
func WithPullSource(source *downloader.Source) PullOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more docs and examples here.
Pull Request Test Coverage Report for Build 9778724044Details
💛 - Coveralls |
pkg/utils/utils.go
Outdated
// MoveFile will move the file from 'src' to 'dest'. | ||
// On windows, it will copy the file from 'src' to 'dest', and then delete the file under 'src'. | ||
// On unix-like systems, it will rename the file from 'src' to 'dest'. | ||
func MoveFile(src, dest string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this issue: #370
pkg/runner/entry.go
Outdated
@@ -23,6 +23,11 @@ import ( | |||
type EntryKind string | |||
|
|||
// Entry is the entry of 'kpm run'. | |||
// 一个编译入口,主要包括 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use English doc comments.
pkg/package/modfile_test.go
Outdated
@@ -245,6 +245,6 @@ func TestGenSource(t *testing.T) { | |||
src, err = GenSource("oci", "oci://ghcr.io/kcl-lang/k8s", "1.24") | |||
assert.Equal(t, err, nil) | |||
assert.Equal(t, src.Oci.Reg, "ghcr.io") | |||
assert.Equal(t, src.Oci.Repo, "kcl-lang/k8s") | |||
assert.Equal(t, src.Oci.Repo, "/kcl-lang/k8s") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add a / for oci.Repo and what's the spec of OCI reg and repo.
pkg/client/run.go
Outdated
type RunOptions struct { | ||
// CompileOptions is the options for kcl compiler. | ||
hasSettingsYaml bool | ||
SettingYamls []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Settings
pkg/client/run.go
Outdated
ro.Option = kcl.NewOption() | ||
} | ||
ro.hasSettingsYaml = true | ||
ro.SettingYamls = settingFiles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SettingYamls or SettingFiles?
} | ||
|
||
// WithStrictRange sets the strict range flag for the kcl package. | ||
func WithStrictRange(strictRange bool) RunOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WithStrictRangeCheck
pkg/client/run.go
Outdated
} | ||
|
||
// NoCompileEntries returns true if there is no compile entries. | ||
func (o *RunOptions) NoCompileEntries() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HasCompileEntries
pkg/client/run.go
Outdated
} | ||
|
||
// Merge merges the options from kcl.yaml which is located in the work directory or inputed by the cli. | ||
func (o *RunOptions) loadYamlSettingsFromLocalAndCli(rootPath string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to know why you new so many names? SettingsYamls, YamlSettings, Settings, SettingFiles...
pkg/client/run.go
Outdated
func (o *RunOptions) loadCliSettings(rootPath string, rootPkgSource *downloader.Source) error { | ||
// If user input is empty, return error. | ||
if o.NoCompileEntries() { | ||
return ErrNoCliSettings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no entris returns no cli settings err message...
pkg/client/run.go
Outdated
} | ||
|
||
// acquire the lock of the package cache. | ||
err := c.AcquirePackageCacheLock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why lock here if we do not load deps from remote sources.
Signed-off-by: zongz <[email protected]>
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
re #289
2. What is the scope of this PR (e.g. component or file name):
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links: