| 1 | ## Getting Started with Development |
| 2 | |
| 3 | These instructions will get you a copy of the project up and running on your |
| 4 | local machine for development, testing, and contribution purposes. |
| 5 | |
| 6 | Please read the [CLI Style Guide](https://github.com/urfave/cli) before |
| 7 | implementing any features or modifying behavior as it contains expectations |
| 8 | surrounding how the CLI should behave. |
| 9 | |
| 10 | All changes to behavior *must* be documented in the [CHANGELOG.md](../CHANGELOG.md). |
| 11 | |
| 12 | ### Prerequisites |
| 13 | |
| 14 | To get started with local development, you will need three things: |
| 15 | |
| 16 | - Golang installed locally (instructions available |
| 17 | [here](https://golang.org/doc/install)). |
| 18 | - A version of `make` available for usage of the `Makefile`. |
| 19 | - The repository checked out in the appropriate location of your `$GOPATH`. |
| 20 | |
| 21 | Ensure you've checked out the repository into the appropriate path inside your |
| 22 | `$GOPATH`. For example, if your `$GOPATH` is set to `~/go`, then you'd check |
| 23 | this repository out at `~/go/src/github.com/smallstep/cli`. You can |
| 24 | learn more about `$GOPATH` in the |
| 25 | [documentation](https://golang.org/doc/code.html#GOPATH). |
| 26 | |
| 27 | ### Installing Dependencies and Bootstrapping |
| 28 | |
| 29 | Once you've cloned the repository to the appropriate location, you will now be |
| 30 | able to install any other dependencies via the `make bootstrap` command. |
| 31 | |
| 32 | You should only ever need to run this command once, as it will ensure you have |
| 33 | the right version of `golangci-lint` installed. |
| 34 | |
| 35 | ### Building step |
| 36 | |
| 37 | To build step, simply run `make build` which will build the cli and place the |
| 38 | binary in the `bin` folder. |
| 39 | |
| 40 | ### Running Tests and Linting |
| 41 | |
| 42 | Now that you've installed any dependencies, you can run the tests and lint the |
| 43 | code base simply by running `make`. |
| 44 | |
| 45 | #### Unit Tests |
| 46 | |
| 47 | Run the unit tests: |
| 48 | |
| 49 | ``` |
| 50 | make test |
| 51 | ``` |
| 52 | |
| 53 | #### Integration Tests |
| 54 | |
| 55 | Run the integration tests: |
| 56 | |
| 57 | ``` |
| 58 | make integration |
| 59 | ``` |
| 60 | |
| 61 | #### And coding style tests |
| 62 | |
| 63 | These tests apply the following `Go` linters to verify code style and formatting: |
| 64 | |
| 65 | * [deadcode](https://github.com/tsenart/deadcode) |
| 66 | * [gofmt](https://golang.org/cmd/gofmt/) |
| 67 | * [golint](https://github.com/golang/lint/golint) |
| 68 | * [ineffassign](https://github.com/gordonklaus/ineffassign) |
| 69 | * [metalinter](https://github.com/alecthomas/gometalinter) |
| 70 | * [misspell](https://github.com/client9/misspell/cmd/misspell) |
| 71 | * [vet](https://golang.org/cmd/vet/) |
| 72 | |
| 73 | ``` |
| 74 | make lint |
| 75 | ``` |
| 76 | |
| 77 | ### Adding and Removing Dependencies |
| 78 | |
| 79 | To add any dependency to the repository, simply import it into your code and |
| 80 | then run `go get <pkg>` which will update the `go.mod` and `go.sum` file. A |
| 81 | specific version of a dependency can be specified by adding it to the `go.mod` |
| 82 | file. |
| 83 | |
| 84 | To remove a dependency, simply remove it from the codebase and any mention of it |
| 85 | in the `go.mod` file and run `go mod tidy` which will remove it from the the |
| 86 | `go.sum` file. |