### Install addlicense CLI Source: https://context7.com/google/addlicense/llms.txt Install the tool using the Go package manager and verify the installation. ```bash # Install the latest version using go install (requires Go 1.16+) go install github.com/google/addlicense@latest # Verify installation addlicense -h ``` -------------------------------- ### Install addlicense Source: https://github.com/google/addlicense/blob/master/README.md Install the latest version of addlicense using the Go toolchain. ```bash go install github.com/google/addlicense@latest ``` -------------------------------- ### Install and Run Pre-commit Hooks Source: https://context7.com/google/addlicense/llms.txt Install the configured pre-commit hooks for your repository. Then, run the addlicense hook manually on all files or only on staged files. ```bash # Install pre-commit hooks pre-commit install # Run manually on all files pre-commit run addlicense --all-files # Run on staged files only pre-commit run addlicense ``` -------------------------------- ### Tagging and Pushing for Release Source: https://github.com/google/addlicense/blob/master/RELEASING.md Start a release by creating a Git tag and pushing it to the repository. This action triggers the automated release workflow. ```sh git tag -a v1.2.3-rc0 git push origin master --tags ``` -------------------------------- ### GitHub Actions Workflow for License Header Check Source: https://context7.com/google/addlicense/llms.txt Example GitHub Actions workflow to automatically check license headers on push or pull requests to the main branch. It includes steps to set up Go, install addlicense, and run the check with specified ignore patterns. ```yaml # .github/workflows/license-check.yaml name: License Header Check on: push: branches: [main] pull_request: branches: [main] jobs: license-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.21' - name: Install addlicense run: go install github.com/google/addlicense@latest - name: Check license headers run: | addlicense -check \ -c "Your Company" \ -ignore "vendor/**" \ -ignore "**/*.md" \ -ignore "**/testdata/**" \ . ``` -------------------------------- ### Run addlicense Source: https://github.com/google/addlicense/blob/master/README.md Execute addlicense on the current directory and all subdirectories. ```bash addlicense . ``` -------------------------------- ### Apply Custom License Templates Source: https://context7.com/google/addlicense/llms.txt Use a custom Go template file to define the license header format. ```bash # Create a custom template file (custom.tpl) cat > custom.tpl << 'EOF' Copyright {{.Year}} {{.Holder}} This is proprietary software. All rights reserved. Unauthorized copying is strictly prohibited. EOF # Apply custom template addlicense -f custom.tpl -c "Acme Corporation" -y 2024 . ``` -------------------------------- ### Run Custom AddLicense Docker Image Source: https://context7.com/google/addlicense/llms.txt Execute your custom-built addlicense Docker image to add or check license headers in your project. Mount your project directory to /src. ```bash docker run -it -v "${PWD}:/src" addlicense -c "Your Company" . ``` -------------------------------- ### Run via Docker Source: https://context7.com/google/addlicense/llms.txt Execute addlicense within a Docker container to avoid local Go dependencies. ```bash # Pull the official image docker pull ghcr.io/google/addlicense:latest # Show help docker run -it ghcr.io/google/addlicense -h # Add license to current directory (mount as /src) docker run -it -v "${PWD}:/src" ghcr.io/google/addlicense \ -c "Your Company" \ -l apache \ . ``` -------------------------------- ### Manage addlicense with Docker Source: https://github.com/google/addlicense/blob/master/README.md Commands for pulling, building, and running addlicense within a Docker container. ```bash docker pull ghcr.io/google/addlicense:latest ``` ```bash docker build -t ghcr.io/google/addlicense . ``` ```bash docker run -it ghcr.io/google/addlicense -h ``` ```bash docker run -it -v ${PWD}:/src ghcr.io/google/addlicense -c "Google LLC" *.go ``` -------------------------------- ### Bash Script for Initializing License Headers Source: https://context7.com/google/addlicense/llms.txt A comprehensive bash script to initialize license headers in a new project. It sets copyright holder, license type, and year, then adds headers to all files while ignoring specified patterns. Finally, it verifies that all files have the correct headers. ```bash #!/bin/bash # setup-license.sh - Initialize license headers in a new project set -e COPYRIGHT_HOLDER="Acme Corporation" LICENSE_TYPE="apache" YEAR=$(date +%Y) # Add license headers to all source files addlicense \ -c "${COPYRIGHT_HOLDER}" \ -l "${LICENSE_TYPE}" \ -y "${YEAR}" \ -v \ -ignore "vendor/**" \ -ignore "node_modules/**" \ -ignore "**/*.md" \ -ignore "**/*.json" \ -ignore "**/*.txt" \ -ignore "**/testdata/**" \ -ignore "**/*.generated.*" \ . echo "License headers added successfully!" # Verify all files have headers echo "Verifying license headers..." if addlicense -check -c "${COPYRIGHT_HOLDER}" \ -ignore "vendor/**" \ -ignore "node_modules/**" \ -ignore "**/*.md" \ -ignore "**/*.json" \ -ignore "**/*.txt" \ -ignore "**/testdata/**" \ -ignore "**/*.generated.*" \ .; then echo "All files have proper license headers!" else echo "Warning: Some files may still be missing headers" exit 1 fi ``` -------------------------------- ### Select License Types Source: https://context7.com/google/addlicense/llms.txt Specify the license type to apply using the -l flag. ```bash # Add MIT license addlicense -l mit -c "John Doe" . # Add BSD license addlicense -l bsd -c "Your Company" . # Add Mozilla Public License 2.0 addlicense -l mpl -c "Your Organization" . # Add Apache 2.0 license (explicit) addlicense -l apache -c "Your Company" . ``` -------------------------------- ### Enable Verbose Output Source: https://context7.com/google/addlicense/llms.txt Display detailed information about file modifications or skipped files. ```bash # Show all files being modified addlicense -v -c "Your Company" . # Combine with check mode to see which files would be modified addlicense -v -check -c "Your Company" . # Example output: # 2024/01/15 10:30:45 src/main.go modified # 2024/01/15 10:30:45 skipping: vendor/lib.go # 2024/01/15 10:30:45 src/utils.py modified ``` -------------------------------- ### Build Custom AddLicense Docker Image Source: https://context7.com/google/addlicense/llms.txt Build your own Docker image for addlicense from the source code. This allows for customization or using a specific version. ```bash docker build -t addlicense . ``` -------------------------------- ### Add Apache License Headers Source: https://context7.com/google/addlicense/llms.txt Apply Apache 2.0 license headers to files with options for custom copyright holders, years, and specific file patterns. ```bash # Add Apache license (default) with default copyright holder "Google LLC" addlicense . # Add Apache license with custom copyright holder addlicense -c "Acme Corporation" . # Add license to specific file patterns addlicense -c "Acme Corporation" *.go *.py src/ # Add license with specific year addlicense -c "Acme Corporation" -y 2023 . # Add license with year range addlicense -c "Acme Corporation" -y "2020-2024" . ``` -------------------------------- ### Configure pre-commit hook Source: https://github.com/google/addlicense/blob/master/README.md Add the addlicense hook to your .pre-commit-config.yaml file. ```yaml repos: - repo: https://github.com/google/addlicense rev: hooks: - id: addlicense args: [ "-c", "Company, Inc", "*.go" ] ``` -------------------------------- ### Configure AddLicense as a Pre-commit Hook Source: https://context7.com/google/addlicense/llms.txt Set up addlicense to automatically run as a pre-commit hook. This ensures license headers are checked or added before each commit. Specify the repository, revision, hook ID, and arguments like company name and license type. ```yaml # .pre-commit-config.yaml repos: - repo: https://github.com/google/addlicense rev: v1.1.1 # Use the latest release tag hooks: - id: addlicense args: - -c - "Your Company, Inc" - -l - apache - -ignore - "vendor/**" - -ignore - "**/testdata/**" ``` -------------------------------- ### Run AddLicense in Docker (Check Mode) Source: https://context7.com/google/addlicense/llms.txt Use this command to check for missing license headers in your project files when running addlicense within a Docker container. Ensure your project directory is mounted to /src. ```bash docker run -it -v "${PWD}:/src" ghcr.io/google/addlicense \ -check \ -c "Your Company" \ . ``` -------------------------------- ### Verify License Headers Source: https://context7.com/google/addlicense/llms.txt Use check mode to validate headers without modifying files, suitable for CI pipelines. ```bash # Check if all files have license headers (exit code 0 if all have headers) addlicense -check . # Check specific directories addlicense -check -c "Expected Holder" src/ lib/ # Check with verbose output showing missing files addlicense -check -v . # Example CI script usage #!/bin/bash if ! addlicense -check -c "Acme Corporation" .; then echo "Error: Some files are missing license headers" exit 1 fi ``` -------------------------------- ### Add SPDX License Identifiers Source: https://context7.com/google/addlicense/llms.txt Include SPDX identifiers in headers for machine-readable license metadata. ```bash # Add full license text with SPDX identifier appended addlicense -s -l apache -c "Your Company" . # Add ONLY SPDX identifier (minimal header) addlicense -s=only -l Apache-2.0 -c "Your Company" . # Use any SPDX identifier with -s=only mode addlicense -s=only -l GPL-3.0-only -c "Your Company" . ``` -------------------------------- ### AddLicense Supported File Types and Comment Styles Source: https://context7.com/google/addlicense/llms.txt This section lists the file extensions and their corresponding comment styles that addlicense automatically detects and supports for adding license headers. ```bash # C-style block comments (/* ... */) # Supported: .c, .h, .java, .scala, .kt, .kts, .gv # JavaScript-style block comments (/** ... */) # Supported: .js, .mjs, .cjs, .jsx, .ts, .tsx, .css, .scss, .sass, .less # Double-slash comments (// ...) # Supported: .go, .cc, .cpp, .cs, .rs, .swift, .dart, .proto, .groovy, .gradle, .php, .hcl, .v, .sv # Hash comments (# ...) # Supported: .py, .rb, .sh, .bash, .yaml, .yml, .toml, .tf, .pl, .dockerfile, .bzl, .nix, .graphql # Semicolon comments (;; ...) # Supported: .el, .lisp, .scm # Double-dash comments (-- ...) # Supported: .hs, .lua, .sql, .sdl # HTML-style comments () # Supported: .html, .htm, .xml, .vue, .svelte # Other special formats # .j2, .jinja, .jinja2: {# ... #} # .ps1, .psm1: <# ... #> # .ml, .mli: (** ... *) # .vim: " ... ``` -------------------------------- ### Run AddLicense in Docker with Ignore Patterns Source: https://context7.com/google/addlicense/llms.txt Execute addlicense within Docker, specifying files or directories to ignore during the license header check. This is useful for excluding generated files or dependencies. ```bash docker run -it -v "${PWD}:/src" ghcr.io/google/addlicense \ -c "Your Company" \ -ignore "vendor/**" \ -ignore "node_modules/**" \ . ``` -------------------------------- ### Exclude Files with Ignore Patterns Source: https://context7.com/google/addlicense/llms.txt Use glob patterns to exclude specific files, directories, or file types from processing. ```bash # Ignore vendor directory addlicense -ignore "vendor/**" -c "Your Company" . # Ignore multiple patterns addlicense \ -ignore "vendor/**" \ -ignore "**/*_test.go" \ -ignore "node_modules/**" \ -ignore "*.generated.go" \ -c "Your Company" . # Ignore specific file types addlicense -ignore "**/*.md" -ignore "**/*.txt" -c "Your Company" . # Complex ignore patterns (doublestar syntax) addlicense \ -ignore "**/testdata/**" \ -ignore "third_party/**" \ -ignore "**/*.pb.go" \ -c "Your Company" . ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.