Skip to content

Commit

Permalink
fix: make list-ecosystems flag actually useful again (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Mar 13, 2022
1 parent 7fdb42c commit 54eccb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,18 @@ which can be useful for debugging issues and general exploring.

#### `--list-ecosystems`

Lists all the ecosystems that exist in the loaded OSV database. This can be
useful when exploring new parsers, or building wrappers around the detector
since a valid ecosystem is required to determine if a package has a
vulnerability, and the ecosystem names are case-sensitive:
Lists all the ecosystems that the detector knows about (aka there is a parser
that results in packages from that ecosystem):

```
$ osv-detector --list-ecosystems
Loaded 6532 vulnerabilities (including withdrawn, last updated Fri, 04 Mar 2022 00:11:50 GMT)
The loaded OSV has vulnerabilities for the following ecosystems:
Packagist
Go
The detector supports parsing for the following ecosystems:
npm
crates.io
RubyGems
npm
Packagist
Go
PyPI
Maven
NuGet
```

#### `--list-packages`
Expand Down
18 changes: 8 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func loadOSVDatabase(offline bool, archiveURL string) database.OSVDatabase {
return *db
}

func printEcosystems(db database.OSVDatabase) {
ecosystems := db.ListEcosystems()
func printKnownEcosystems() {
ecosystems := lockfile.KnownEcosystems()

fmt.Println("The loaded OSV has vulnerabilities for the following ecosystems:")
fmt.Println("The detector supports parsing for the following ecosystems:")

for _, ecosystem := range ecosystems {
fmt.Printf(" %s\n", ecosystem)
Expand Down Expand Up @@ -135,6 +135,11 @@ func main() {
os.Exit(0)
}

if *listEcosystems {
printKnownEcosystems()
os.Exit(0)
}

pathToLockOrDirectory := flag.Arg(0)

packages, err := lockfile.Parse(pathToLockOrDirectory, *parseAs)
Expand All @@ -151,13 +156,6 @@ func main() {

dbs := loadEcosystemDatabases(packages.Ecosystems(), *offline)

if *listEcosystems {
for _, db := range dbs {
printEcosystems(db)
}
os.Exit(0)
}

file := path.Base(pathToLockOrDirectory)

knownVulnerabilitiesCount := 0
Expand Down

0 comments on commit 54eccb9

Please sign in to comment.