src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

main.go (943B)


      1 // Copyright 2022 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package main
      6 
      7 import (
      8 	"context"
      9 	"errors"
     10 	"fmt"
     11 	"os"
     12 
     13 	"golang.org/x/telemetry"
     14 	"golang.org/x/vuln/scan"
     15 )
     16 
     17 func main() {
     18 	telemetry.Start(telemetry.Config{ReportCrashes: true})
     19 
     20 	ctx := context.Background()
     21 
     22 	cmd := scan.Command(ctx, os.Args[1:]...)
     23 	err := cmd.Start()
     24 	if err == nil {
     25 		err = cmd.Wait()
     26 	}
     27 	if err != nil {
     28 		var e interface{ ExitCode() int }
     29 		if errors.As(err, &e) {
     30 			printErrorToStderr := true
     31 			if _, ok := err.(interface{ ExitCode() int }); ok {
     32 				// Avoid printing the error to stderr if the exit code error wasn't
     33 				// wrapped with another error providing context.
     34 				printErrorToStderr = false
     35 			}
     36 			if printErrorToStderr {
     37 				fmt.Fprintln(os.Stderr, err)
     38 			}
     39 			os.Exit(e.ExitCode())
     40 		}
     41 		fmt.Fprintln(os.Stderr, err)
     42 		os.Exit(1)
     43 	}
     44 }