Categorygithub.com/jeeftor/license-manager
module
0.4.0
Repository: https://github.com/jeeftor/license-manager.git
Documentation: pkg.go.dev

# README

License Manager

pre-commit Go Report Card License

GitHub commit activity GitHub commits since latest release GitHub Release Date GitHub Downloads (all assets, all releases) GitHub Repo stars

docs/logo.png 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.

Go Report Card License

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.

Dynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON Badge
Dynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON Badge
Dynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON Badge
Dynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON BadgeDynamic JSON Badge
Dynamic JSON Badge

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 --inputs 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

CommandDescription
addAdd license headers to files
build-test-dataGenerate test files for all supported languages
checkCheck license headers in files (this can also be used as a pre-commit hook)
completionGenerate the autocompletion script for the specified shell
debugDebug license markers in files
helpHelp about any command
pre-commitRun license checks on specified files
removeRemove license headers from files
stylesList available license header styles
updateUpdate license headers in files
versionPrint 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 block
  • box: Boxed comment style
  • line: 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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.

# Packages

cmd/root.go.
No description provided by the author