# README
License Manager
A CLI tool and a Pre-Commit Hook for managing license headers in source code files. This tool helps you add, remove, update, and check license headers across your codebase with ease and precision. It utilizes non-printing Unicode character to mark the start & end of the License comment such that you can easier update or remove the license information.
Features
- Add License Headers: Automatically add license headers to files that don't have them
- Remove License Headers: Clean up license headers from files
- Update License Headers: Replace existing license headers with new content
- Check License Headers: Verify if files have the correct license headers
- Multiple File Support: Process multiple files using glob patterns
- Customizable Comment Styles: Supports various programming language comment styles
- Dry Run Mode: Preview changes before applying them
- Interactive Mode: Confirm changes for each file
- Verbose Output: Detailed logging for better visibility
- Skip Patterns: Exclude specific files or directories
- Preset Header Styles: Choose from predefined header/footer styles
Fully Tested Languages
This is a list of languages that have been fully mostly tested.
Installation
The following details CLI based installation. License manager can also be used as a docs/pre-commit.md hook.
License Manager
A CLI tool for managing license headers in source code files. This tool helps you add, remove, update, and check license headers across your codebase with ease and precision. It utilizes non-printing Unicode character to mark the start & end of the License comment such that you can easier update or remove the license information.
Installation
You can install the License Manager through several methods:
Using Homebrew (macOS and Linux)
The easiest way to install on macOS and Linux is through Homebrew:
# Add the tap repository
brew tap jeeftor/tap
# Install the package
brew install license-manager
To upgrade to the latest version:
brew upgrade license-manager
Using Debian Package (Ubuntu/Debian)
For Debian-based Linux distributions, you can download and install the .deb package:
# Download the latest release
curl -LO "https://github.com/jeeftor/license-manager/releases/latest/download/license-manager_$(curl -s https://api.github.com/repos/jeeftor/license-manager/releases/latest | grep tag_name | cut -d '"' -f 4 | cut -c 2-)_linux_amd64.deb"
# Install the package
sudo dpkg -i license-manager_*_linux_amd64.deb
# Install dependencies if needed
sudo apt-get install -f
You can also download the .deb package directly from the releases page.
Using Go
If you prefer to install using Go:
go install github.com/jeeftor/license-manager/cmd/license-manager@latest
From Source
For the latest development version:
git clone https://github.com/jeeftor/license-manager.git
cd license-manager
go build
Usage
Basic Commands
The basic arguments required are to include 1 or more --input
s to give a pattern of files to add licenses to and a --license
file. Additionally you may want to include one or more --skip
patterns to ensure you aren't adding licenses say to your ./vendor
directory.
Here are some basic examples
# Add license headers to go and python files - ignoring a .venv directory
license-manager add --license LICENSE.txt --input "**/*.go" --input "**/*.py" --skip "./venv/**"
# Remove license headers
license-manager remove --input "**/*.go" --input "**/*.py" --skip "./vendor/**" --skip "./venv/**"
# Update existing license headers to use a new license and the swords style
license-manager update --license NEW_LICENSE.txt --input "**/*.go" --style swords
# Check license headers
license-manager check --license LICENSE.txt --input "**/*.go"
Commands
Command | Description |
---|---|
add | Add license headers to files |
build-test-data | Generate test files for all supported languages |
check | Check license headers in files (this can also be used as a pre-commit hook) |
completion | Generate the autocompletion script for the specified shell |
debug | Debug license markers in files |
help | Help about any command |
pre-commit | Run license checks on specified files |
remove | Remove license headers from files |
styles | List available license header styles |
update | Update license headers in files |
version | Print version information |
Command Options
--license
string Path to license text file (required for add/update/check)--input
strings Input file patterns (can be comma-separated or multiple flags)--skip
strings Patterns to skip (can be comma-separated or multiple flags)--style
string Preset style for header/footer (default "hash")--comments
string Force comment style (no|single|multi)--log-level
string Log level (debug|info|notice|warn|error) (default "notice")
Examples
# Add license headers to all Go files, excluding tests
license-manager add --license LICENSE.txt --input "**/*.go" --skip "**/*_test.go"
# Update license headers in Python files with confirmation
license-manager update --license NEW_LICENSE.txt --input "**/*.py" --prompt
# Check license headers in JavaScript files with detailed output
license-manager check --license LICENSE.txt --input "**/*.js" --verbose
# Remove license headers from C++ files in dry-run mode
license-manager remove --input "**/*.cpp" --dry-run
Configuration
Comment Styles
The tool automatically detects appropriate comment styles based on file extensions:
- Go:
// comment
- Python:
# comment
- JavaScript/TypeScript:
// comment
- C/C++:
/* comment */
- And many more...
Header Styles
Choose from various preset header/footer styles using the --preset-style
flag:
standard
: Simple comment blockbox
: Boxed comment styleline
: Line-separated comments- And more...
Building from Source
Requirements:
- Go 1.19 or higher
# Clone the repository
git clone https://github.com/yourusername/license-manager.git
# Change to project directory
cd license-manager
# Build the project
go build
# Run tests
go test ./...
# Install locally
go install
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with Cobra for CLI interface
- Inspired by various license management tools in the open-source community
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.