Categorygithub.com/pyama86/pachanger
repositorypackage
0.1.0
Repository: https://github.com/pyama86/pachanger.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

pachanger

pachanger is a CLI tool that renames a Go package and updates all references in other files accordingly.

Installation

You can install pachanger using Go:

Go

% go install github.com/pyama86/pachanger@latest

Homebrew

% 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

Usage

Basic Command

% pachanger --file <target-file> --new <new-package-name> [--output <output-directory>] [--workdir <working-directory>]

Options

  • --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: "").

Check Version

% pachanger version

Examples

Rename a package

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

Specify a working directory

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

Using Standard Input

% cat file.list | pachanger --new example --file -

How It Works

  1. The package name in the specified --file is changed to --new.
  2. The modified file is saved in the --output directory.
  3. The tool scans .go files in --workdir and updates references accordingly.
  4. The code is formatted automatically using goimports.

For Developers

Build

% go build -o pachanger ./cmd

Run Tests

% make test

License

MIT License

Author

pyama86