mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix: implement MainModuleOnly filter correctly in ShouldInclude()
- Added IsMainModule field to PackageInfo to track main module membership - Updated buildPackageStore() to populate IsMainModule for all packages - Modified ShouldInclude() to check MainModuleOnly parameter - Now correctly filters out packages from submodules when --main-only flag is used The MainModuleOnly parameter was previously defined but never actually used in the filtering logic, making the --main-only flag ineffective.
This commit is contained in:
@ -56,6 +56,7 @@ type PackageInfo struct {
|
||||
Imports []string // Direct imports of this package
|
||||
IsStdLib bool // Standard library marker (from go list)
|
||||
IsModuleRoot bool // Is this the root package of its module
|
||||
IsMainModule bool // Is this package from the main module (not a submodule)
|
||||
}
|
||||
|
||||
// FilterOptions represents filtering criteria for dependency analysis.
|
||||
@ -320,6 +321,11 @@ func (opts *FilterOptions) Normalize(modulePrefix string) error {
|
||||
|
||||
// ShouldInclude determines if a package should be included based on filter options.
|
||||
func (opts *FilterOptions) ShouldInclude(pkg *PackageInfo) bool {
|
||||
// Filter by main module only (exclude submodules)
|
||||
if opts.MainModuleOnly && !pkg.IsMainModule {
|
||||
return false
|
||||
}
|
||||
|
||||
// Filter by kind
|
||||
switch pkg.Kind {
|
||||
case KindStdLib:
|
||||
@ -633,10 +639,11 @@ func (a *analyzer) buildPackageStore() *PackageStore {
|
||||
// Convert go packages to PackageInfo
|
||||
for path, goPkg := range a.packages {
|
||||
pkgInfo := &PackageInfo{
|
||||
ImportPath: path,
|
||||
ModulePath: goPkg.Module.Path,
|
||||
IsStdLib: goPkg.Standard,
|
||||
Imports: goPkg.Imports,
|
||||
ImportPath: path,
|
||||
ModulePath: goPkg.Module.Path,
|
||||
IsStdLib: goPkg.Standard,
|
||||
Imports: goPkg.Imports,
|
||||
IsMainModule: a.isMainModulePackage(path),
|
||||
}
|
||||
pkgInfo.Kind = store.identifyPackageKind(pkgInfo)
|
||||
store.packages[path] = pkgInfo
|
||||
|
||||
Reference in New Issue
Block a user