Skip to content
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

Parse package patterns args #139

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading