Skip to content

Commit

Permalink
add comments on functions and use constant variables
Browse files Browse the repository at this point in the history
Signed-off-by: Asish Kumar <[email protected]>
  • Loading branch information
officialasishkumar committed Aug 17, 2024
1 parent aaa4610 commit f4bb91a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,15 @@ func AbsTarPath(tarPath string) (string, error) {
return absTarPath, nil
}

// FindPackage finds the package with the package name 'targetPackage' under the 'root' directory kcl.mod file.
func FindPackage(root, targetPackage string) (string, error) {
var result string
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
kclModPath := filepath.Join(path, "kcl.mod")
kclModPath := filepath.Join(path, constants.KCL_MOD)
if _, err := os.Stat(kclModPath); err == nil {
if matchesPackageName(kclModPath, targetPackage) {
result = path
Expand All @@ -628,6 +629,7 @@ func FindPackage(root, targetPackage string) (string, error) {
return result, nil
}

// MatchesPackageName checks whether the package name in the kcl.mod file under 'kclModPath' is equal to 'targetPackage'.
func matchesPackageName(kclModPath, targetPackage string) bool {
type Package struct {
Name string `toml:"name"`
Expand Down

0 comments on commit f4bb91a

Please sign in to comment.