File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ gotools:
4646godeps : gotools
4747 $(GO ) mod download
4848
49+ gotidy :
50+ ./scripts/gomate.sh tidy
51+
4952fpc-sdk : godeps
5053 $(foreach DIR, $(FPC_SDK_DEP_DIRS ) , $(MAKE ) -C $(DIR ) build || exit;)
5154
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ #
3+ # Copyright IBM Corp. All Rights Reserved.
4+ #
5+ # SPDX-License-Identifier: Apache-2.0
6+ #
7+
8+ set -euo pipefail
9+
10+ # lint me: shfmt -i 2 -ci -l -w
11+
12+ IFS=$' \t\n ' # Split on newlines and tabs (but not on spaces)
13+ script_name=$( basename " ${0} " )
14+ script_dir=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd)
15+ readonly script_name script_dir
16+
17+ readonly repo_dir=" $( pwd) "
18+
19+ # how to use this script
20+ function usage() {
21+ cli_name=${0##*/ }
22+ echo " gomate helps to manage multiple go modules in a single repository.
23+ Usage: $cli_name [command]
24+ Commands:
25+ initwork creates go workspace for this project (\` go work init\` and \` go work use\` everywhere)
26+ tidy runs \` go mod tidy\` everywhere
27+ update [XYZ] updates a specific dep (\` go get XYZ\` ) everywhere; if no dep argument given, \` go get -u\` is called
28+ help shows this help
29+ "
30+ exit 1
31+ }
32+
33+ # create go work init
34+ function init_work() {
35+ echo " go work init"
36+ go work init
37+ find " $repo_dir " -iname " go.mod" -exec dirname {} \; | xargs go work use
38+ }
39+
40+ # update deps; take as parameter the dependency to update; if empty all deps are updates
41+ function update() {
42+ if [[ -z $1 ]]; then
43+ # check all update
44+ echo " go get -u everywhere"
45+ find " $repo_dir " -iname " go.mod" -execdir sh -c " go get -u" \;
46+ else
47+ # check a specific dep
48+ echo " go get $1 everywhere"
49+ find " $repo_dir " -iname " go.mod" -execdir sh -c " go get $1 " \;
50+ fi
51+ }
52+
53+ # run go mod tidy everywhere
54+ function tidy() {
55+ echo " go mod tidy everywhere"
56+ find " $repo_dir " -iname " go.mod" -execdir sh -c " go mod tidy" \;
57+ }
58+
59+ main () {
60+ case " ${1-" " } " in
61+ initwork)
62+ init_work
63+ ;;
64+ tidy)
65+ tidy
66+ ;;
67+ update)
68+ update " ${2-" " } "
69+ ;;
70+ * )
71+ usage
72+ ;;
73+ esac
74+ }
75+
76+ main " ${@ } "
You can’t perform that action at this time.
0 commit comments