Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.0.0-20201105173854-bc9fc8d8c4bc / go / packages / example_test.go
1 package packages_test
2
3 import (
4         "flag"
5         "fmt"
6         "os"
7
8         "golang.org/x/tools/go/packages"
9 )
10
11 // Example demonstrates how to load the packages specified on the
12 // command line from source syntax.
13 func Example() {
14         flag.Parse()
15
16         // Many tools pass their command-line arguments (after any flags)
17         // uninterpreted to packages.Load so that it can interpret them
18         // according to the conventions of the underlying build system.
19         cfg := &packages.Config{Mode: packages.NeedFiles | packages.NeedSyntax}
20         pkgs, err := packages.Load(cfg, flag.Args()...)
21         if err != nil {
22                 fmt.Fprintf(os.Stderr, "load: %v\n", err)
23                 os.Exit(1)
24         }
25         if packages.PrintErrors(pkgs) > 0 {
26                 os.Exit(1)
27         }
28
29         // Print the names of the source files
30         // for each package listed on the command line.
31         for _, pkg := range pkgs {
32                 fmt.Println(pkg.ID, pkg.GoFiles)
33         }
34 }