From 5395b08dcaec3f8f6e2d45d0aa7ee7c118bc36a4 Mon Sep 17 00:00:00 2001 From: Pranav Gaikwad Date: Wed, 24 Apr 2024 09:29:58 -0400 Subject: [PATCH] :sparkles: add --incident-selector and --context-lines Signed-off-by: Pranav Gaikwad --- cmd/analyze.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/analyze.go b/cmd/analyze.go index 85b6e16..817e0f8 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -68,6 +68,8 @@ type analyzeCommand struct { httpProxy string httpsProxy string noProxy string + contextLines int + incidentSelector string // tempDirs list of temporary dirs created, used for cleanup tempDirs []string @@ -178,6 +180,8 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command { analyzeCommand.Flags().StringVar(&analyzeCmd.httpProxy, "http-proxy", loadEnvInsensitive("http_proxy"), "HTTP proxy string URL") analyzeCommand.Flags().StringVar(&analyzeCmd.httpsProxy, "https-proxy", loadEnvInsensitive("https_proxy"), "HTTPS proxy string URL") analyzeCommand.Flags().StringVar(&analyzeCmd.noProxy, "no-proxy", loadEnvInsensitive("no_proxy"), "proxy excluded URLs (relevant only with proxy)") + analyzeCommand.Flags().IntVar(&analyzeCmd.contextLines, "context-lines", 100, "number of lines of source code to include in the output for each incident") + analyzeCommand.Flags().StringVar(&analyzeCmd.incidentSelector, "incident-selector", "", "an expression to select incidents based on custom variables. ex: (!package=io.konveyor.demo.config-utils)") return analyzeCommand } @@ -733,13 +737,18 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string, c args := []string{ fmt.Sprintf("--provider-settings=%s", ProviderSettingsMountPath), fmt.Sprintf("--output-file=%s", AnalysisOutputMountPath), - fmt.Sprintf("--context-lines=%d", 100), + fmt.Sprintf("--context-lines=%d", a.contextLines), } if a.enableDefaultRulesets { args = append(args, fmt.Sprintf("--rules=%s/", RulesetPath)) } + if a.incidentSelector != "" { + args = append(args, + fmt.Sprintf("--incident-selector=%s", a.incidentSelector)) + } + if len(a.rules) > 0 { args = append(args, fmt.Sprintf("--rules=%s/", CustomRulePath))