-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgo-work-init.sh
More file actions
66 lines (56 loc) · 1.53 KB
/
Copy pathgo-work-init.sh
File metadata and controls
66 lines (56 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 Provability-Fabric Contributors
#
# Create a local go.work from go.work.example (gitignored).
# Default local DX for multi-module Go work — prefer this over treating
# each go.mod as an isolated island.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
EXAMPLE="${GO_WORK_EXAMPLE:-go.work.example}"
TARGET="${GO_WORK_TARGET:-go.work}"
SYNC=0
FORCE=0
usage() {
cat <<'EOF'
Usage: scripts/go-work-init.sh [--force] [--sync]
Copies go.work.example -> go.work (gitignored) for local multi-module Go work.
Options:
--force Overwrite an existing go.work
--sync Run `go work sync` after creating go.work
-h|--help Show this help
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--force) FORCE=1 ;;
--sync) SYNC=1 ;;
-h|--help) usage; exit 0 ;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
shift
done
if [[ ! -f "$EXAMPLE" ]]; then
echo "Missing $EXAMPLE — cannot initialize Go workspace." >&2
exit 1
fi
if [[ -f "$TARGET" && "$FORCE" -ne 1 ]]; then
echo "$TARGET already exists (use --force to overwrite from $EXAMPLE)."
else
cp "$EXAMPLE" "$TARGET"
echo "Wrote $TARGET from $EXAMPLE"
fi
if [[ "$SYNC" -eq 1 ]]; then
if ! command -v go >/dev/null 2>&1; then
echo "go not found on PATH; skipped go work sync" >&2
exit 1
fi
go work sync
echo "go work sync completed"
fi
echo "Go workspace ready. Primary CLI: core/cli/pf (see CONTRIBUTING.md)."