From cae3eec631dc4994400e7c27e85a0c0e645f607b Mon Sep 17 00:00:00 2001 From: Ramana Reddy <90540245+RamanaReddy0M@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:50:45 +0530 Subject: [PATCH] Add option to list cve-ids (#16) --- main.go | 15 ++++++++++++--- types.go | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 3225743..db0bdf8 100644 --- a/main.go +++ b/main.go @@ -106,6 +106,7 @@ func main() { flagset.CreateGroup("OUTPUT", "output", flagset.EnumSliceVarP(&options.includeColumns, "field", "f", []goflags.EnumVariable{goflags.EnumVariable(-1)}, strings.Replace(fmt.Sprintf("fields to display in cli output. supported: %s", allowedHeaderString), " ,", "", -1), allowedHeader), flagset.EnumSliceVarP(&options.excludeColumns, "exclude", "fe", []goflags.EnumVariable{goflags.EnumVariable(-1)}, strings.Replace(fmt.Sprintf("fields to exclude from cli output. supported: %s", allowedHeaderString), " ,", "", -1), allowedHeader), + flagset.BoolVarP(&options.listId, "list-id", "lid", false, "list only the cve ids in the output"), flagset.IntVarP(&options.limit, "limit", "l", 50, "limit the number of results to display"), flagset.BoolVarP(&options.json, "json", "j", false, "return output in json format"), ) @@ -200,10 +201,18 @@ func main() { return } - if options.json { - if options.limit > len(cvesResp.Cves) { - options.limit = len(cvesResp.Cves) + if options.limit > len(cvesResp.Cves) { + options.limit = len(cvesResp.Cves) + } + + if options.listId { + for _, cve := range cvesResp.Cves[:options.limit] { + fmt.Println(cve.CveID) } + return + } + + if options.json { outputJson(cvesResp.Cves[:options.limit]) return } diff --git a/types.go b/types.go index 552747f..6fd28ae 100644 --- a/types.go +++ b/types.go @@ -19,6 +19,7 @@ type Options struct { //vulnType goflags.StringSlice includeColumns []string excludeColumns []string + listId bool epssScore string cpe string vulnStatus string