Add module rename script
This commit is contained in:
parent
680e63a4f8
commit
e620c55272
2 changed files with 46 additions and 0 deletions
9
reformat.sh
Executable file
9
reformat.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e -o pipefail
|
||||||
|
|
||||||
|
GO_FILES=$(find . -name "*.go" | grep -v .git)
|
||||||
|
|
||||||
|
gofumpt -l -w $GO_FILES
|
||||||
|
gofmt -l -w $GO_FILES
|
||||||
|
gci write $GO_FILES
|
||||||
37
rename-module.sh
Executable file
37
rename-module.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e -o pipefail
|
||||||
|
|
||||||
|
OLD_MODULE_NAME="github.com/tailscale/wireguard-go"
|
||||||
|
NEW_MODULE_NAME="github.com/sagernet/wireguard-go"
|
||||||
|
|
||||||
|
rules=$(cat <<EOF
|
||||||
|
id: replace-module
|
||||||
|
language: go
|
||||||
|
rule:
|
||||||
|
kind: import_spec
|
||||||
|
pattern: \$OLD_IMPORT
|
||||||
|
constraints:
|
||||||
|
OLD_IMPORT:
|
||||||
|
has:
|
||||||
|
field: path
|
||||||
|
regex: ^"$OLD_MODULE_NAME
|
||||||
|
transform:
|
||||||
|
NEW_IMPORT:
|
||||||
|
replace:
|
||||||
|
source: \$OLD_IMPORT
|
||||||
|
replace: $OLD_MODULE_NAME(?<PATH>.*)
|
||||||
|
by: $NEW_MODULE_NAME\$PATH
|
||||||
|
fix: \$NEW_IMPORT
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
sg scan --inline-rules "$rules" -U
|
||||||
|
|
||||||
|
sed -i "s|module $OLD_MODULE_NAME|module $NEW_MODULE_NAME|" go.mod
|
||||||
|
|
||||||
|
go mod tidy
|
||||||
|
|
||||||
|
./reformat.sh
|
||||||
|
|
||||||
|
git commit -m "Rename module" -a
|
||||||
Loading…
Add table
Add a link
Reference in a new issue