Modern CLI tool to manage copyright headers across multiple languages with Git integration and SPDX support
Project description
Copyright CLI Tool
A professional, multi-language copyright header management tool. Ensure compliance, maintain consistency, and manage project licensing with ease.
Features
Core Capabilities
- Multi-Language Support: Support for Python, JavaScript, TypeScript, Java, C/C++, Go, Rust, and Shell scripts.
- Intelligent Year Management: Automatic year range management with full 4-digit years (e.g., 2024-2026).
- Header Removal: Seamlessly strip copyright headers from files for open-source contributions.
- Git Integration: Automatic discovery of company name and email from Git configurations.
- SPDX Compliance: Full support for SPDX license identifiers and machine-readable formats.
- Configuration Layers: Flexible settings via .copyright.toml, pyproject.toml, or user-wide configuration.
- Validation Suite: Verify compliance in CI/CD pipelines without modifying source files.
- Preview Mode: Safely review pending changes using dry-run and verbose logging.
Installation
pip install copyright-cli-tool
Or install from source:
git clone https://github.com/rohan7654/copyright-cli-tool.git
cd copyright-cli-tool
pip install -e .
Quick Start
# Add copyright headers to current directory
copyright
# Specify company name
copyright --company "AcmeCorp"
# Use SPDX format with license
copyright --license MIT --format spdx
# Preview changes without modifying files
copyright --dry-run --verbose
# Validate headers in CI/CD
copyright --check
Usage
Basic Usage
# Process current directory with auto-detected company
copyright
# Specify path and company
copyright --path ./src --company "AcmeCorp"
# Add email to headers
copyright --company "AcmeCorp" --email "info@acmecorp.com"
Multi-Language Projects
# Process multiple file types
copyright --extensions .py .js .ts .java
# Process JavaScript/TypeScript project
copyright --extensions .js .ts .jsx .tsx
Exclusion Patterns
# Exclude specific patterns
copyright --exclude "tests/*" "docs/*" "*_test.py"
# Ignore .gitignore patterns
copyright --no-gitignore
SPDX Format
# Use SPDX format with license identifier
copyright --license MIT --format spdx
# Traditional format (default)
copyright --license MIT --format traditional
SPDX Format Output:
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2026 AcmeCorp <info@acmecorp.com>
Traditional Format Output:
# Copyright 2026 AcmeCorp. All rights reserved.
Validation Mode (CI/CD)
# Check if all files have valid headers
copyright --check
# Check with verbose output
copyright --check --verbose
# Exit code: 0 if valid, 1 if invalid
Dry-Run Mode
# Preview what would change
copyright --dry-run
# See detailed changes
copyright --dry-run --verbose
Remove Mode
The tool provides a dedicated mode for stripping copyright headers from source files. This is particularly useful for contributors preparing code for open-source repositories where project-wide headers are managed separately.
# Remove copyright headers from all Python files
copyright --remove
# Remove from specific file types
copyright --remove --extensions .py .js .ts
# Preview removal without modifying files
copyright --remove --dry-run --verbose
# Remove from specific directory
copyright --path ./src --remove
Configuration
Create a .copyright.toml file in your project root or ~/.copyright.toml for user-wide settings:
[tool.copyright]
company = "AcmeCorp"
email = "info@acmecorp.com"
license = "MIT"
format = "traditional"
file_extensions = [".py", ".js", ".ts", ".java"]
exclude = [
"tests/*",
"docs/*",
"*_test.py"
]
Or add to your pyproject.toml:
[tool.copyright]
company = "AcmeCorp"
email = "info@acmecorp.com"
license = "Apache-2.0"
format = "spdx"
Configuration Priority
When resolving properties like the company name or email, the tool follows a layered priority system:
- Command-line arguments: Flags provided directly to the CLI.
- Local Configuration:
.copyright.tomlin the current working directory. - Project Metadata:
[tool.copyright]section inpyproject.toml. - User Defaults:
~/.copyright.tomlin the user home directory. - Auto-discovery: Intelligence gathered from Git config (
user.name,user.email). - Interactive Prompt: If all previous layers fail to provide a company name, the tool will gracefully prompt for interactive input.
Advanced Usage
Pre-commit Hook
Add to your .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: copyright-check
name: Check copyright headers
entry: copyright --check
language: system
pass_filenames: false
always_run: true
GitHub Actions
Create .github/workflows/copyright-check.yml:
name: Copyright Check
on: [pull_request, push]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: pip install copyright-cli-tool
- run: copyright --check --company "Your Company"
GitLab CI
Add to your .gitlab-ci.yml:
copyright-check:
stage: test
image: python:3.10
script:
- pip install copyright-cli-tool
- copyright --check --company "Your Company"
Supported Languages
| Language | Extensions | Comment Style |
|---|---|---|
| Python | .py | # |
| JavaScript | .js, .jsx, .mjs | // |
| TypeScript | .ts, .tsx | // |
| Java | .java | // |
| C | .c, .h | // |
| C++ | .cpp, .hpp, .cc, .hh, .cxx | // |
| Go | .go | // |
| Rust | .rs | // |
| Shell | .sh, .bash | # |
Command-Line Options
usage: copyright [-h] [--version] [--path PATH] [--company COMPANY]
[--email EMAIL] [--license LICENSE]
[--format {traditional,spdx}]
[--extensions EXTENSIONS [EXTENSIONS ...]]
[--exclude EXCLUDE [EXCLUDE ...]] [--config CONFIG]
[--dry-run] [--check] [--remove] [--verbose] [--no-gitignore]
Options:
-h, --help Show this help message and exit
--version, -v Show program's version number and exit
--path PATH, -p PATH Directory path to scan (default: current directory)
--company COMPANY, -c COMPANY
Company name for copyright header
--email EMAIL, -e EMAIL
Email address for copyright header
--license LICENSE, -l LICENSE
SPDX license identifier (e.g., MIT, Apache-2.0)
--format {traditional,spdx}, -f {traditional,spdx}
Header format (default: traditional)
--extensions EXTENSIONS [EXTENSIONS ...]
File extensions to process (e.g., .py .js .ts)
--exclude EXCLUDE [EXCLUDE ...]
Glob patterns to exclude (e.g., 'tests/*' 'docs/*')
--config CONFIG Path to custom configuration file
--dry-run, -n Preview changes without modifying files
--check Validate headers without modification (exit 1 if issues)
--remove, -r Remove copyright headers from files
--verbose Show detailed output for each file
--no-gitignore Don't respect .gitignore patterns
Examples
Example 1: New Project Setup
# Initialize copyright headers for a Python project
copyright --company "MyCompany" --license MIT
# Or use configuration file
cat > .copyright.toml << EOF
[tool.copyright]
company = "MyCompany"
license = "MIT"
file_extensions = [".py"]
EOF
copyright
Example 2: Multi-Language Project
# Process Python, JavaScript, and TypeScript files
copyright --company "TechCorp" \
--extensions .py .js .ts \
--exclude "node_modules/*" "dist/*"
Example 3: SPDX Compliance
# Use SPDX format for open-source project
copyright --company "OpenSource Inc" \
--email "oss@example.com" \
--license Apache-2.0 \
--format spdx
Example 4: CI/CD Integration
# In CI pipeline
copyright --check --company "CI Corp"
# With custom config
copyright --check --config .copyright.toml
Year Range Logic
The tool intelligently manages copyright year ranges with full 4-digit years:
| Existing Header | Current Year | Result |
|---|---|---|
| Copyright 2025 AcmeCorp. All rights... | 2026 | Copyright 2025-2026 AcmeCorp. All rights... |
| Copyright 2025-2026 AcmeCorp. All rights.. | 2026 | (unchanged) |
| (no header) | 2026 | Copyright 2026 AcmeCorp. All rights... |
| Copyright 2024-2025 AcmeCorp. All rights.. | 2026 | Copyright 2024-2026 AcmeCorp. All rights... |
Troubleshooting
Issue: Git auto-detection not working
Solution: Ensure you're in a git repository and have configured git:
git config user.name "Your Name"
git config user.email "your@email.com"
Issue: Files not being processed
Solution: Check if files are excluded by .gitignore or default exclusions. Use --no-gitignore or --verbose to debug.
Issue: Unsupported file type
Solution: The file extension may not be supported yet. Check the supported languages table above.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests if applicable
- Run tests:
pytest - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
git clone https://github.com/rohan7654/copyright-cli-tool.git
cd copyright-cli-tool
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
License
This project is licensed under the MIT License - see the LICENSE file for details.
You are free to:
- Use the software commercially
- Modify and distribute the code
- Include it in private or open-source projects
Under the following conditions:
- The original copyright and license notice must be included
- The software is provided "as is", without warranty of any kind
Support
If you encounter any issues or have questions:
- Open a GitHub Issue
- Include clear steps to reproduce the issue
- Provide environment details (OS, Python version, etc.)
Changelog
See CHANGELOG.md for a detailed history of changes.
Acknowledgments
- Built with Rich for beautiful terminal output
- Inspired by tools like addlicense, licenseheaders, and HashiCorp Copywrite
- Thanks to all contributors and users
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file copyright_cli_tool-0.1.0.tar.gz.
File metadata
- Download URL: copyright_cli_tool-0.1.0.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9a1d27499ec02288d82b45f2f8cfdb1750fda8095b723c64383bf14bcf5a072
|
|
| MD5 |
899057a7f0c780c4194906b7c322ca5f
|
|
| BLAKE2b-256 |
c2b9b1f5f88825bd624fb8b57a39672e446d77da652d888e8db6feac3b134bb0
|
File details
Details for the file copyright_cli_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: copyright_cli_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3c24670de092b7561d24dae1c239e801ce4f0263c91f36aa59d74cb5c5e3ab6
|
|
| MD5 |
44916b0304308139dad17d1a3dd9e057
|
|
| BLAKE2b-256 |
faf2e9f015b2abde1d778bb29fd4901291c5c62e42995db7ee2157756755a21a
|