Isolate query params

This commit is contained in:
abhisek 2023-02-03 14:43:04 +05:30
parent 4e5b5412c2
commit c8248ce9bd
No known key found for this signature in database
GPG Key ID: CB92A4990C02A88F

View File

@ -9,10 +9,11 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// We will re-use the variable declarations in scan.go var (
// since query.go is a subset of scan function where queryFilterExpression string
// data is loaded from JSON instead of lockfiles and enriched queryLoadDirectory string
// with backend queryEnableConsoleReport bool
)
func newQueryCommand() *cobra.Command { func newQueryCommand() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -24,11 +25,11 @@ func newQueryCommand() *cobra.Command {
}, },
} }
cmd.Flags().StringVarP(&dumpJsonManifestDir, "from", "F", "", cmd.Flags().StringVarP(&queryLoadDirectory, "from", "F", "",
"The directory to load JSON dump files") "The directory to load JSON dump files")
cmd.Flags().StringVarP(&celFilterExpression, "filter", "", "", cmd.Flags().StringVarP(&queryFilterExpression, "filter", "", "",
"Filter and print packages using CEL") "Filter and print packages using CEL")
cmd.Flags().BoolVarP(&consoleReport, "report-console", "", false, cmd.Flags().BoolVarP(&queryEnableConsoleReport, "report-console", "", false,
"Minimal summary of package manifest") "Minimal summary of package manifest")
return cmd return cmd
@ -46,8 +47,8 @@ func internalStartQuery() error {
reporters := []reporter.Reporter{} reporters := []reporter.Reporter{}
enrichers := []scanner.PackageMetaEnricher{} enrichers := []scanner.PackageMetaEnricher{}
if !utils.IsEmptyString(celFilterExpression) { if !utils.IsEmptyString(queryFilterExpression) {
task, err := analyzer.NewCelFilterAnalyzer(celFilterExpression) task, err := analyzer.NewCelFilterAnalyzer(queryFilterExpression)
if err != nil { if err != nil {
return err return err
} }
@ -55,7 +56,7 @@ func internalStartQuery() error {
analyzers = append(analyzers, task) analyzers = append(analyzers, task)
} }
if consoleReport { if queryEnableConsoleReport {
rp, err := reporter.NewConsoleReporter() rp, err := reporter.NewConsoleReporter()
if err != nil { if err != nil {
return err return err
@ -68,5 +69,5 @@ func internalStartQuery() error {
TransitiveAnalysis: false, TransitiveAnalysis: false,
}, enrichers, analyzers, reporters) }, enrichers, analyzers, reporters)
return pmScanner.ScanDumpDirectory(dumpJsonManifestDir) return pmScanner.ScanDumpDirectory(queryLoadDirectory)
} }