Skip to content

Commit

Permalink
Parse package patterns args
Browse files Browse the repository at this point in the history
  • Loading branch information
podtserkovskiy committed Oct 31, 2024
1 parent 4e8264a commit cef7a70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmd/scip-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ var (

// Debugging flag to turn on profiling
profileRate int

// Package patterns to index
packagePatterns []string
)

func init() {
Expand Down Expand Up @@ -86,6 +89,8 @@ func init() {
app.Flag("command", "Optionally specifies a command to run. Defaults to 'index'").Default("index").StringVar(&scipCommand)

app.Flag("profile", "Turn on debug profiling. This will reduce performance. Do not turn on unless debugging. Set to number of milliseconds per sample").Default("0").IntVar(&profileRate)

app.Arg("package-patterns", "Package patterns to index. Default: './...' which indexes all packages in the current directory recursively. For the full syntax of allowed package patterns, see https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns").Default("./...").StringsVar(&packagePatterns)
}

func main() {
Expand Down Expand Up @@ -135,7 +140,7 @@ func mainErr() error {
log.Info("Skipping tests")
}

options := config.New(moduleRoot, moduleVersion, modulePath, goVersion, isStdLib, skipImplementations, skipTests)
options := config.New(moduleRoot, moduleVersion, modulePath, goVersion, isStdLib, skipImplementations, skipTests, packagePatterns)

if strings.HasPrefix(scipCommand, "list-packages") {
var filter string
Expand Down
6 changes: 5 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ type IndexOpts struct {
SkipTests bool

IsIndexingStdlib bool

// Package patterns to index
PackagePatterns []string
}

func New(ModuleRoot, ModuleVersion, ModulePath, GoStdlibVersion string, IsIndexingStdlib bool, SkipImplementations bool, SkipTests bool) IndexOpts {
func New(ModuleRoot, ModuleVersion, ModulePath, GoStdlibVersion string, IsIndexingStdlib bool, SkipImplementations bool, SkipTests bool, PackagePatterns []string) IndexOpts {
ModuleRoot, err := filepath.Abs(ModuleRoot)
if err != nil {
panic(err)
Expand All @@ -33,5 +36,6 @@ func New(ModuleRoot, ModuleVersion, ModulePath, GoStdlibVersion string, IsIndexi
SkipImplementations: SkipImplementations,
SkipTests: SkipTests,
IsIndexingStdlib: IsIndexingStdlib,
PackagePatterns: PackagePatterns,
}
}
7 changes: 6 additions & 1 deletion internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ func LoadPackages(
}()

cfg := getConfig(moduleRoot, opts)
pkgs, err := packages.Load(cfg, "./...")
patterns := opts.PackagePatterns
if len(patterns) == 0 {
patterns = append(patterns, "./...")
log.Warn("No target patterns provided using default './...'")
}
pkgs, err := packages.Load(cfg, patterns...)
if err != nil {
return err
}
Expand Down

0 comments on commit cef7a70

Please sign in to comment.