Repository navigation
Expand file tree
/
Copy pathupdate-header
More file actions
executable file
·64 lines (54 loc) · 1.8 KB
/
Copy pathupdate-header
File metadata and controls
executable file
·64 lines (54 loc) · 1.8 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
#!/usr/bin/env bash
set -euo pipefail
# Run from the project root, even when invoked from another directory.
ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd -- "$ROOT"
usage() {
cat <<'HELP'
Usage: ./update-header [--check]
Add missing license headers to Rust files under src/.
--check checks for missing headers without modifying files.
Existing headers and source comments are preserved; years are not rewritten.
Environment overrides:
COPYRIGHT_HOLDER Default: CharOfString
COPYRIGHT_EMAIL Default: Git user.email (required unless supplied)
COPYRIGHT_YEAR Default: current year (also accepts a year range)
ADDLICENSE Default: addlicense (executable name or absolute path)
Install dependency:
go install github.com/google/addlicense@latest
export PATH="$(go env GOPATH)/bin:$PATH"
HELP
}
args=()
case "${1:-}" in
'') ;;
--check) args+=(-check) ;;
-h|--help) usage; exit 0 ;;
*) usage >&2; exit 2 ;;
esac
if (( $# > 1 )); then
usage >&2
exit 2
fi
ADDLICENSE="${ADDLICENSE:-addlicense}"
if ! command -v "$ADDLICENSE" >/dev/null 2>&1; then
printf 'Error: Missing addlicense: %s\n' "$ADDLICENSE" >&2
usage >&2
exit 127
fi
COPYRIGHT_EMAIL="${COPYRIGHT_EMAIL:-$(git config user.email || true)}"
if [[ -z "$COPYRIGHT_EMAIL" ]]; then
echo 'Error: Set COPYRIGHT_EMAIL or configure Git user.email' >&2
exit 1
fi
# Explicitly select Rust sources; never traverse target/, .git/, or dependencies.
mapfile -d '' -t files < <(find src -type f -name '*.rs' -print0)
if (( ${#files[@]} == 0 )); then
echo 'Error: No Rust source files under src/' >&2
exit 1
fi
exec "$ADDLICENSE" "${args[@]}" \
-f scripts/license-header.txt \
-c "${COPYRIGHT_HOLDER:-CharOfString} <$COPYRIGHT_EMAIL>" \
-y "${COPYRIGHT_YEAR:-$(date +%Y)}" \
-v "${files[@]}"