func main() { flag.Parse() // Get the file/directory to analyze. if len(flag.Args()) != 1 { shipshapeUsage() os.Exit(returnError) } thirdPartyAnalyzers := []string{} if *analyzerImages != "" { thirdPartyAnalyzers = strings.Split(*analyzerImages, ",") } cats := []string{} if *categories != "" { cats = strings.Split(*categories, ",") } options := cli.Options{ File: flag.Arg(0), ThirdPartyAnalyzers: thirdPartyAnalyzers, Build: *build, TriggerCats: cats, Dind: *dind, Event: *event, Repo: *repo, StayUp: *stayUp, Tag: *tag, LocalKythe: *useLocalKythe, } if *jsonOutput == "" { options.HandleResponse = outputAsText } else { var allResponses rpcpb.ShipshapeResponse options.HandleResponse = func(msg *rpcpb.ShipshapeResponse, _ string) error { allResponses.AnalyzeResponse = append(allResponses.AnalyzeResponse, msg.AnalyzeResponse...) return nil } options.ResponsesDone = func() error { // TODO(ciera): these results aren't sorted. They should be sorted by path and start line b, err := json.Marshal(allResponses) if err != nil { return err } return ioutil.WriteFile(*jsonOutput, b, 0644) } } numResults, err := cli.New(options).Run() if err != nil { fmt.Printf("Error: %v", err.Error()) os.Exit(returnError) } if numResults != 0 { os.Exit(returnFindings) } os.Exit(returnNoFindings) }
func main() { flag.Parse() // Get the file/directory to analyze. // If we are just showing category list, default to the current directory file := "." if len(flag.Args()) >= 1 { file = flag.Arg(0) } else if !*showCategories { shipshapeUsage() os.Exit(returnError) } thirdPartyAnalyzers := []string{} if *analyzerImages != "" { thirdPartyAnalyzers = strings.Split(*analyzerImages, ",") } cats := []string{} if *categories != "" { cats = strings.Split(*categories, ",") } options := cli.Options{ File: file, ThirdPartyAnalyzers: thirdPartyAnalyzers, Build: *build, TriggerCats: cats, Dind: *dind, Event: *event, Repo: *repo, StayUp: *stayUp, Tag: *tag, LocalKythe: *useLocalKythe, } if *jsonOutput == "" { options.HandleResponse = outputAsText } else { // TODO(supertri): Does not work for showCategories var allResponses rpcpb.ShipshapeResponse options.HandleResponse = func(msg *rpcpb.ShipshapeResponse, _ string) error { allResponses.AnalyzeResponse = append(allResponses.AnalyzeResponse, msg.AnalyzeResponse...) return nil } options.ResponsesDone = func() error { // TODO(ciera): these results aren't sorted. They should be sorted by path and start line b, err := json.Marshal(allResponses) if err != nil { return err } return ioutil.WriteFile(*jsonOutput, b, 0644) } } invocation := cli.New(options) numResults := 0 var err error = nil if *showCategories { err = invocation.ShowCategories() } else if *hotStart { err = invocation.StartService() } else { numResults, err = invocation.Run() } if err != nil { fmt.Printf("Error: %v\n", err.Error()) os.Exit(returnError) } if numResults != 0 { os.Exit(returnFindings) } os.Exit(returnNoFindings) }