pachanger is a CLI tool that renames a Go package and updates all references in other files accordingly.
You can install pachanger using Go:
% go install github.com/pyama86/pachanger@latest
% brew install pyama86/homebrew-ptools/pachanger
Alternatively, you can clone the repository and build the binary manually:
% git clone https://github.com/pyama86/pachanger.git
% cd pachanger
% go build -o pachanger ./cmd
% pachanger --file <target-file> --new <new-package-name> [--output <output-directory>] [--workdir <working-directory>]
--file
The target file to change the package name (required).--new
The new package name (required).--output
Directory to save the modified file (default: same directory as input file).--workdir
Working directory (default: current directory).--add-prefix
Add the prefix to the symbol name (default: "").--delete-prefix
Delete the prefix of the symbol name (default: "").--tags
Build tags to consider when scanning files (default: "").
% pachanger version
Rename the package in model/example.go
to example
and save the modified file in out/
:
% pachanger --file model/example.go --new example --output model/example
Set src
as the working directory and rename the package in model/example.go
to example
:
% pachanger --file model/example.go --new example --workdir src
% cat file.list | pachanger --new example --file -
- The package name in the specified
--file
is changed to--new
. - The modified file is saved in the
--output
directory. - The tool scans
.go
files in--workdir
and updates references accordingly. - The code is formatted automatically using
goimports
.
% go build -o pachanger ./cmd
% make test
MIT License