-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script to rename a go package
- Loading branch information
1 parent
b080d6c
commit 78c77c9
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
if [[ $# -ne 2 ]]; then | ||
echo "usage: $0 {name-before} {name-after}" 1>&2 | ||
exit 1 | ||
fi | ||
name_before=$1 | ||
shift | ||
name_after=$1 | ||
shift | ||
|
||
basename_before=$(basename $name_before) | ||
basename_after=$(basename $name_after) | ||
|
||
git mv $name_before $name_after | ||
|
||
for file in $(find $name_after -type f -name \*.go); do | ||
cat $file | sed -e "s|^package $basename_before|package $basename_after|g" \ | ||
-e "s|^// Package $basename_before|// Package $basename_after|g" > $file.tmp | ||
cat $file.tmp > $file | ||
rm $file.tmp | ||
done | ||
|
||
pkg_prefix=github.com/ooni/probe-cli/v3 | ||
pkg_before=$pkg_prefix/$name_before | ||
pkg_after=$pkg_prefix/$name_after | ||
|
||
for file in $(find . -type f -name \*.go); do | ||
cat $file | sed -e "s|\"$pkg_before\"|\"$pkg_after\"|g" > $file.tmp | ||
cat $file.tmp > $file | ||
rm $file.tmp | ||
done |