github.com/google/osv-scalibr@v0.4.1/linter/plugger/main.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // The plugger command is used to flag plugins which are not registered 16 package main 17 18 import ( 19 "flag" 20 "fmt" 21 "log" 22 "os" 23 24 "github.com/google/osv-scalibr/linter/plugger/flags" 25 "github.com/google/osv-scalibr/linter/plugger/plugger" 26 ) 27 28 var ( 29 fInterfaces flags.List 30 ) 31 32 func setFlags() { 33 flag.Var(&fInterfaces, "interface", `list of interfaces (repeatable), ex: '-interface github.com/pkg.Interface'`) 34 } 35 36 func main() { 37 setFlags() 38 flag.Parse() 39 40 pkgs := flag.Args() 41 42 if len(fInterfaces) == 0 { 43 log.Fatal("please provide at least one plugin interface, ex: '-interface github.com/pkg.Interface'") 44 } 45 46 ctrs, err := plugger.Run(fInterfaces, pkgs) 47 if err != nil { 48 log.Fatal(err) 49 } 50 51 cwd, err := os.Getwd() 52 if err != nil { 53 log.Fatal(err) 54 } 55 56 for _, c := range ctrs { 57 pos, err := c.Pos(cwd) 58 if err != nil { 59 log.Fatal(err) 60 } 61 fmt.Printf("%s: plugger: %s is not registered\n", pos, c.Registers()) 62 } 63 64 if len(ctrs) != 0 { 65 os.Exit(1) 66 } 67 }