|
1 | 1 | # example-golang
|
| 2 | + |
| 3 | +An example repository to demonstrate Pants's experimental Golang support. |
| 4 | + |
| 5 | +See [] for some unique benefits Pants brings to Golang repositories, and see |
| 6 | +[pantsbuild.org/docs/go-overview](https://www.pantsbuild.org/v2.8/docs/go-overview) for much more detailed |
| 7 | +documentation. |
| 8 | + |
| 9 | +This is only one possible way of laying out your project with Pants. See |
| 10 | +[pantsbuild.org/docs/source-roots#examples](https://www.pantsbuild.org/docs/source-roots#examples) |
| 11 | +for some other example layouts. |
| 12 | + |
| 13 | +Note: for now, Pants only supports repositories using a single `go.mod`. Please comment on |
| 14 | +[#13114](https://github.com/pantsbuild/pants/issues/13114) if you need support for greater |
| 15 | +than one `go.mod` so that we can prioritize adding support. |
| 16 | + |
| 17 | +# Running Pants |
| 18 | + |
| 19 | +You run Pants goals using the `./pants` wrapper script, which will bootstrap the |
| 20 | +configured version of Pants if necessary. |
| 21 | + |
| 22 | +# Goals |
| 23 | + |
| 24 | +Pants commands are called _goals_. You can get a list of goals with |
| 25 | + |
| 26 | +``` |
| 27 | +./pants help goals |
| 28 | +``` |
| 29 | + |
| 30 | +Most goals take arguments to run on. To run on a single directory, use the directory name with |
| 31 | +`:` at the end. To recursively run on a directory and all its subdirectories, add `::` to the |
| 32 | +end. |
| 33 | + |
| 34 | +For example: |
| 35 | + |
| 36 | +``` |
| 37 | +./pants lint cmd: internal:: |
| 38 | +``` |
| 39 | + |
| 40 | +You can run on all changed files: |
| 41 | + |
| 42 | +``` |
| 43 | +./pants --changed-since=HEAD lint |
| 44 | +``` |
| 45 | + |
| 46 | +You can run on all changed files, and any of their "dependees": |
| 47 | + |
| 48 | +``` |
| 49 | +./pants --changed-since=HEAD --changed-dependees=transitive test |
| 50 | +``` |
| 51 | + |
| 52 | +# Example Goals |
| 53 | + |
| 54 | +Try these out in this repo! |
| 55 | + |
| 56 | +## Run Gofmt |
| 57 | + |
| 58 | +``` |
| 59 | +./pants fmt :: # Format all packages. |
| 60 | +./pants fmt cmd/greeter_en: # Format only this package. |
| 61 | +./pants lint pkg:: # Check that all packages under `pkg` are formatted. |
| 62 | +``` |
| 63 | + |
| 64 | +## Check compilation |
| 65 | + |
| 66 | +``` |
| 67 | +./pants check :: # Compile all packages. |
| 68 | +./pants check cmd/greeter_en: # Compile only this package and its transitive dependencies. |
| 69 | +``` |
| 70 | + |
| 71 | +## Run tests |
| 72 | + |
| 73 | +``` |
| 74 | +./pants test :: # Run all tests in the repository. |
| 75 | +./pants test pkg/uuid: # Run all the tests in this package. |
| 76 | +./pants test pkg/uuid: -- -run TestGenerateUuid # Run just this one test. |
| 77 | +``` |
| 78 | + |
| 79 | +## Create a binary file |
| 80 | + |
| 81 | +Writes the result to the `dist/` folder. |
| 82 | + |
| 83 | +``` |
| 84 | +./pants package cmd/greeter_en: |
| 85 | +./pants package cmd:: # Create all binaries. |
| 86 | +``` |
| 87 | + |
| 88 | +## Run a binary |
| 89 | + |
| 90 | +``` |
| 91 | +./pants run cmd/greeter_en: |
| 92 | +./pants run cmd/greeter_es: -- --help |
| 93 | +``` |
| 94 | + |
| 95 | +## Determine dependencies |
| 96 | + |
| 97 | +``` |
| 98 | +./pants dependencies cmd/greeter_en: |
| 99 | +./pants dependencies --transitive cmd/greeter_en: |
| 100 | +``` |
| 101 | + |
| 102 | +## Determine dependees |
| 103 | + |
| 104 | +That is, find what code depends on a particular package(s). |
| 105 | + |
| 106 | +``` |
| 107 | +./pants dependees pkg/uuid: |
| 108 | +./pants dependees --transitive pkg/uuid: |
| 109 | +``` |
| 110 | + |
| 111 | +## Count lines of code |
| 112 | + |
| 113 | +``` |
| 114 | +./pants count-loc '**/*' |
| 115 | +``` |
0 commit comments