Metadata-Version: 2.4
Name: copyright-cli-tool
Version: 0.1.0
Summary: Modern CLI tool to manage copyright headers across multiple languages with Git integration and SPDX support
Author-email: Rohan <rohanroni2019@gmail.com>
License-Expression: MIT
Keywords: copyright,license,header,spdx,cli,automation
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: toml>=0.10.0
Requires-Dist: rich>=13.0.0
Requires-Dist: gitpython>=3.1.0
Dynamic: license-file

# 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

```bash
pip install copyright-cli-tool
```

Or install from source:

```bash
git clone https://github.com/rohan7654/copyright-cli-tool.git
cd copyright-cli-tool
pip install -e .
```

## Quick Start

```bash
# 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

```bash
# 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

```bash
# Process multiple file types
copyright --extensions .py .js .ts .java

# Process JavaScript/TypeScript project
copyright --extensions .js .ts .jsx .tsx
```

### Exclusion Patterns

```bash
# Exclude specific patterns
copyright --exclude "tests/*" "docs/*" "*_test.py"

# Ignore .gitignore patterns
copyright --no-gitignore
```

### SPDX Format

```bash
# Use SPDX format with license identifier
copyright --license MIT --format spdx

# Traditional format (default)
copyright --license MIT --format traditional
```

**SPDX Format Output:**

```python
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2026 AcmeCorp <info@acmecorp.com>
```

**Traditional Format Output:**

```python
# Copyright 2026 AcmeCorp. All rights reserved.
```

### Validation Mode (CI/CD)

```bash
# 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

```bash
# 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.

```bash
# 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:

```toml
[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`:

```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:

1. **Command-line arguments**: Flags provided directly to the CLI.
2. **Local Configuration**: `.copyright.toml` in the current working directory.
3. **Project Metadata**: `[tool.copyright]` section in `pyproject.toml`.
4. **User Defaults**: `~/.copyright.toml` in the user home directory.
5. **Auto-discovery**: Intelligence gathered from Git config (`user.name`, `user.email`).
6. **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`:

```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`:

```yaml
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`:

```yaml
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

```bash
# 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

```bash
# Process Python, JavaScript, and TypeScript files
copyright --company "TechCorp" \
          --extensions .py .js .ts \
          --exclude "node_modules/*" "dist/*"
```

### Example 3: SPDX Compliance

```bash
# 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

```bash
# 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:

```bash
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:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests if applicable
5. Run tests: `pytest`
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

### Development Setup

```bash
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](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](https://github.com/rohan7654/copyright-cli-tool/issues)
- Include clear steps to reproduce the issue
- Provide environment details (OS, Python version, etc.)

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes.

## Acknowledgments

- Built with [Rich](https://github.com/Textualize/rich) for beautiful terminal output
- Inspired by tools like addlicense, licenseheaders, and HashiCorp Copywrite
- Thanks to all contributors and users

---

**Made with care by Rohan** | [GitHub](https://github.com/rohan7654/copyright-cli-tool) | [Issues](https://github.com/rohan7654/copyright-cli-tool/issues)
