-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add API for checker and support mod checking in update (#557)
* feat: add API for checker and support mod checking in update Signed-off-by: zongz <zongzhe1024@163.com> * fix: fix test cases Signed-off-by: zongz <zongzhe1024@163.com> * fix: fix test cases Signed-off-by: zongz <zongzhe1024@163.com> --------- Signed-off-by: zongz <zongzhe1024@163.com>
- Loading branch information
Showing
21 changed files
with
375 additions
and
115 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"kcl-lang.io/kpm/pkg/checker" | ||
pkg "kcl-lang.io/kpm/pkg/package" | ||
) | ||
|
||
type CheckOptions struct { | ||
KclMod *pkg.KclPkg | ||
} | ||
|
||
type CheckOption func(*CheckOptions) error | ||
|
||
func WithCheckKclMod(kclMod *pkg.KclPkg) CheckOption { | ||
return func(opts *CheckOptions) error { | ||
if kclMod == nil { | ||
return fmt.Errorf("kclMod cannot be nil") | ||
} | ||
opts.KclMod = kclMod | ||
return nil | ||
} | ||
} | ||
|
||
func (c *KpmClient) Check(options ...CheckOption) error { | ||
opts := &CheckOptions{} | ||
for _, option := range options { | ||
if err := option(opts); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
kmod := opts.KclMod | ||
if kmod == nil { | ||
return fmt.Errorf("kclMod cannot be nil") | ||
} | ||
|
||
// Init the ModChecker, name and version checkers are required. | ||
if c.ModChecker == nil || c.ModChecker.CheckersSize() == 0 { | ||
c.ModChecker = checker.NewModChecker( | ||
checker.WithCheckers( | ||
checker.NewIdentChecker(), | ||
checker.NewVersionChecker(), | ||
checker.NewSumChecker(), | ||
), | ||
) | ||
} | ||
|
||
// Check the module and the dependencies | ||
err := c.ModChecker.Check(*kmod) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
Oops, something went wrong.