|
| 1 | +# gomod-sync |
| 2 | + |
| 3 | +Utility tool to check and update the Go version specified in the `go.mod` files of all exercises. |
| 4 | +It works by specifying the desired Go version for all the `go.mod` files to be in. The `check` command |
| 5 | +will verify if all `go.mod` files are in the desired version and the `update` command will update all |
| 6 | +`go.mod` files to have the desired Go version. |
| 7 | + |
| 8 | +Some exercises must have its `go.mod` specify a Go version that is different from the other exercise's `go.mod`. |
| 9 | +This is supported by the `exceptions` key of the configuration file, where an entry must exist for each exercise |
| 10 | +that must not have the default version. |
| 11 | + |
| 12 | +## Quick start |
| 13 | + |
| 14 | +To update all go.mod files according to the config file (gomod-sync/config.json) run: |
| 15 | + |
| 16 | +```console |
| 17 | +$ cd gomod-sync |
| 18 | +$ go run main.go update |
| 19 | +``` |
| 20 | + |
| 21 | +To check all exercise go.mod files specify the correct Go version, run: |
| 22 | + |
| 23 | +```console |
| 24 | +$ cd gomod-sync |
| 25 | +$ go run main.go check |
| 26 | +``` |
| 27 | + |
| 28 | +## Installing |
| 29 | + |
| 30 | +### Compiling locally |
| 31 | + |
| 32 | +```console |
| 33 | +$ cd gomod-sync |
| 34 | +$ go build |
| 35 | +``` |
| 36 | + |
| 37 | +This will create an executable `gomod-sync` (`gomod-sync.exe` in windows) in the current directory |
| 38 | +that you can run to execute the program. |
| 39 | + |
| 40 | +### Running without compiling |
| 41 | + |
| 42 | +```console |
| 43 | +$ cd gomod-sync |
| 44 | +$ go run main.go <command> [flags] |
| 45 | +``` |
| 46 | + |
| 47 | +### Running the tests |
| 48 | + |
| 49 | +```console |
| 50 | +$ cd gomod-sync |
| 51 | +$ go test ./... |
| 52 | +``` |
| 53 | + |
| 54 | +## Usage |
| 55 | + |
| 56 | +``` |
| 57 | + gomod-sync commandUpdate gitig [flags] |
| 58 | +
|
| 59 | +Available Commands: |
| 60 | + check Checks if all go.mod files are in the target version |
| 61 | + update Updates go.mod files to the target version |
| 62 | + help Help about any command |
| 63 | +
|
| 64 | +``` |
| 65 | + |
| 66 | +## Commands |
| 67 | + |
| 68 | +- `gomod-sync check -v target_version [-e exercises_path] [-c config_file]` |
| 69 | + |
| 70 | + checks if all `go.mod` files are in the target version |
| 71 | + |
| 72 | +- `gomod-sync completion` |
| 73 | + |
| 74 | + generate the autocompletion script for the specified shell |
| 75 | +- `gomod-sync help` |
| 76 | + |
| 77 | + Help about any command |
| 78 | +- `gomod-sync list [-e exercises_path]` |
| 79 | + |
| 80 | + list `go.mod` files and the Go version they specify |
| 81 | +- `gomod-sync update -v target_version [-e exercises_path] [-c config_file]` |
| 82 | + |
| 83 | + updates `go.mod` files to the target version |
| 84 | + |
| 85 | +## Flags |
| 86 | + |
| 87 | +- `-c, --config config_file` |
| 88 | + |
| 89 | + path to the JSON configuration file. (default `"config.json"`) |
| 90 | + |
| 91 | +- `-e, --exercises exercises_path` |
| 92 | + |
| 93 | + path to the exercises folder. `go.mod` files will be recursively searched inside this directory. (default `"../exercises"`) |
| 94 | +- `-v, --goversion target_version` |
| 95 | + |
| 96 | + target go version that all go.mod files are expected to have. |
| 97 | + This will be used to check if the `go.mod` files are in the expected version in case of the check command, |
| 98 | + and to update all `go.mod` files to this version in the case of the update command. |
| 99 | + Using this flag will override the version specified in the config file. |
| 100 | + |
| 101 | +- `-h, --help` |
| 102 | + |
| 103 | + help for gomod-sync |
| 104 | + |
| 105 | + |
| 106 | +## Configuration file |
| 107 | + |
| 108 | +Besides the `-v, --goversion` flag, it is also possible to specify the expected go versions for the `go.mod` files in a JSON configuration file. |
| 109 | +This file can be given to the program with the `-c, --config file` flag. If the flag is omitted, a file `config.json` |
| 110 | +in the current directory will be tried. |
| 111 | + |
| 112 | +With a configuration file, in addition to define a default Go version all exercises' `go.mod` must have, |
| 113 | +it's also possible to configure different versions for different exercises. This can be useful if a particular exercise |
| 114 | +needs a superior version of Go than the default. |
| 115 | + |
| 116 | +This an example of such configuration file: |
| 117 | + |
| 118 | +```json |
| 119 | +{ |
| 120 | + "default": "1.16", |
| 121 | + "exceptions": [ |
| 122 | + { |
| 123 | + "exercise": "strain", |
| 124 | + "version": "1.18" |
| 125 | + } |
| 126 | + ] |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +With such configuration, all `go.mod` files will be expected to have the `1.16` version of Go, |
| 131 | +except the exercise `strain`, which must have version `1.18` in its `go.mod`. |
| 132 | +Specifying the `-v, --goversion` flag overrides the default version specified in this file. |
| 133 | + |
| 134 | +## Examples |
| 135 | + |
| 136 | + |
| 137 | +* Check if all `go.mod` files of exercises in the `../exercises` folder have the default version |
| 138 | + specified in the `config.json` file: |
| 139 | + |
| 140 | + * `gomod-sync check` |
| 141 | + |
| 142 | +* Check if all `go.mod` files of exercises in the `exercises` folder have the `1.16` Go version: |
| 143 | + |
| 144 | + * `gomod-sync check --goversion 1.16 --exercises ./exercises` |
| 145 | + |
| 146 | +* Update all `go.mod` files of exercises in the `exercises` folder have the `1.16` Go version: |
| 147 | + |
| 148 | + * `gomod-sync update --goversion 1.16 --exercises ./exercises` |
| 149 | + |
| 150 | +* Update all `go.mod` files, using a config file to specify the versions of exercises: |
| 151 | + |
| 152 | + * `gomod-sync update --config a_dir/config.json --exercises ./exercises` |
0 commit comments