Skip to content

Seamless source code license management from your command line

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

ekkolon/licensa

Licensa

codecov Crates.io Version docs.rs Crates.io License (version)

Licensa is a powerful CLI tool designed for seamless source code license management. Developers can effortlessly verify, apply, modify, and enforce SPDX license headers across their source code.

As of today, Licensa boasts compatibility with over 65 file types, making it a versatile and comprehensive solution for license management in diverse coding environments.

You may be looking for:

Overview

Explore the complete CLI reference for a comprehensive list of options.

init Generate project-wide Licensa configuration.

licensa init [OPTIONS]

apply Add SPDX copyright license headers to source code files.

licensa apply [OPTIONS]

verify Verify presence of license headers in source code files.

licensa verify

Installation

Cargo

cargo install licensa

Linux

Licensa currently supports the following architectures:

  • x86_64 (64-bit Intel/AMD processors)
  • aarch64 (64-bit ARM processors)

Run the following command and follow the on-screen instructions:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/ekkolon/licensa/main/scripts/install.sh)"

This script will:

  • automatically detect your machine's architecture
  • download and unpack the necessary .tar
  • copy the licensa binary to usr/local/bin

For more details, you can review the installation script directly.

Windows (PowerShell)

Before running the installation script, ensure that your PowerShell execution policy allows (remote) script execution. You can set the execution policy using the following command:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Executing the following script will walk you through the installation process (you may need to run this command from an elevated shell):

Invoke-Expression -Command (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/ekkolon/licensa/main/scripts/install.ps1" -UseBasicParsing).Content

Usage

This is an example walkthrough

Suppose you have a TypeScript project "Lord Of The Rings Map" (lotr-map) with the following initial structure:

.
└── lotr-map/
    ├── node_modules/
    ├── src/
    │   ├── map/
    │   │   └── Terrain.ts    # has license header
    │   ├── Rivendell.ts      # no license header
    │   ├── Isengard.ts       # no license header
    │   ├── Mithrandir.ts     # has license header
    │   ├── Gondor.ts         # has license header
    │   └── MinasTirith.ts    # has license header
    ├── .gitignore  
    ├── package.json
    └── tsconfig.json

Generate project-wide Licensa configurations

When a .licensarc config file is present, required arguments in subsequent commands become optional if they are already defined in the config file.

Licensa includes a pre-built .licensaignore file, akin to a .gitignore, allowing you to specify patterns for including/excluding files from the licensing process.

To generate project-wide configurations, execute the following command:

licensa init --type Apache-2.0 --owner "Eru Ilúvata" --year 2001

Upon successful execution, the command will expand your project structure to include the .licensarc and .licensaignore:

.
└── lotr-map/
    ├── node_modules/
    ├── src/
    │   ├── map/
    │   │   └── Terrain.ts    # has license header
    │   ├── Rivendell.ts      # no license header
    │   ├── Isengard.ts       # no license header
    │   ├── Mithrandir.ts     # has license header
    │   ├── Gondor.ts         # has license header
    │   └── MinasTirith.ts    # has license header
    ├── .gitignore  
    ├── .licensaignore        # ADDED
    ├── .licensarc            # ADDED
    ├── package.json
    └── tsconfig.json

The generated .licensarc config file would contain the following settings:

{
  "type": "Apache-2.0",
  "owner": "Eru Ilúvata",
  "year": 2001
}

Add license headers to your source files

Expanding on the project layout described earlier, it's noted that three source files already have SPDX license headers applied to them. Consequently, these files are excluded from the licensing process.

With defaults from .licensarc config file

licensa apply
src/Rivendell.ts
/**
 * Copyright 2001 Eru Ilúvata
 * SPDX-License-Identifier: Apache-2.0
 */

import Terrain from './map/Terrain.ts';

export class Rivendell extends Terrain {}
src/Isengard.ts
/**
 * Copyright 2001 Eru Ilúvata
 * SPDX-License-Identifier: Apache-2.0
 */

import Terrain from './map/Terrain.ts';

export class Isengard extends Terrain {}

Override defaults with supplied options

licensa apply --type AGPL-3.0-only --owner Sauron --year "2002-present"
src/Rivendell.ts
/**
 * Copyright 2002-present Sauron
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import Terrain from './map/Terrain.ts';

export class Rivendell extends Terrain {}
src/Isengard.ts
/**
 * Copyright 2002-present Sauron
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import Terrain from './map/Terrain.ts';

export class Isengard extends Terrain {}

CLI Reference

Commands

init

Generate project-wide Licensa configuration.

licensa init [OPTIONS]

apply

Add SPDX copyright license headers to source code files.

licensa apply [OPTIONS]

verify

Verify presence of license headers in source code files.

licensa verify

Options

-t, --type required SPDX License identifier (case-insensitive)

Optional, if present in .licensarc config file

default: N/A

-o, --owner required The copyright owner

Optional, if present in .licensarc config file

default: N/A

--year The copyright year or a range of years

default: null

--exclude A list of glob patterns to exclude from the licensing process

Globals

--verbose Detailed command output

-h, --help Show help message

-v, --version Show program's version number

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.