Skip to content
isocialPracticePublic

About

A command-line tool that fetches common open source licenses and generates LICENSE files for your projects.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

gnlcn - Generate License CLI icon.png

A command-line tool that fetches common open source licenses and generates LICENSE files for your projects.

Features

  • Fetch licenses from GitHub's License API
  • Generate LICENSE files with customizable copyright holder and year
  • Configure a default user for convenience
  • Name the copyright holder from where a repository sits, with a user and organization pattern
  • Read a LICENSE file's license, year and holder, offline
  • Support for common license aliases (e.g., mit, apache, gpl)

Installation

npm install -g gnlcn

Or install locally in your project:

npm install gnlcn

Usage

Generate a License

# Generate an MIT license
gnlcn mit -u JohnDoe

# Generate with a name containing spaces (use quotes)
gnlcn mit -u "John Doe"

# Generate an Apache 2.0 license
gnlcn apache-2.0 -u JaneDoe

# Generate with a specific year
gnlcn mit -u "Acme Corp" -y 2025

Set a Default User

Set a default username so you don't need to specify -u every time:

gnlcn --config-user JohnDoe

# Or with spaces (use quotes)
gnlcn --config-user "John Doe"

After setting a default user, simply run:

gnlcn mit

Override Default User

Even with a default user set, you can override it:

gnlcn mit -u DifferentUser

List Available Licenses

gnlcn --list

Output:

Available licenses:

  mit             MIT License
  apache-2.0      Apache License 2.0
  gpl-3.0         GNU General Public License v3.0
  bsd-3-clause    BSD 3-Clause "New" or "Revised" License
  ...

Usage: gnlcn <license-key> [options]
Example: gnlcn mit -u "John Doe"

Custom Output Path

gnlcn mit -u JohnDoe -o ./my-project/LICENSE

Options

Option Alias Description
--config-user <username> -c Set the default username for future use. Username must be alphanumeric with optional spaces [a-zA-Z0-9 ]+ (use quotes for spaces).
--user [username] -u Copyright holder name. Required if --config-user has not been set. Supports spaces when quoted.
--year [year] -y Copyright year (4 digits). Defaults to current year.
--output <path> -o Output file path. Defaults to LICENSE. With --read, the file to read.
--list -l List all available licenses.
--define <path> <name> -d Save the pattern: the root folder of your repositories, and the holder of the repositories directly in it. See The User and Organization Pattern.
--pattern -p Write the license with the holder the pattern gives the current repository. Cannot be used with --user.
--read[:<qualifier>] -r Read the license file and print its details, or only one value with a qualifier (-r:user).
--help -h Display help information.
--version -V Display version number.

User Resolution Logic

The tool implements sophisticated user resolution:

  1. --config-user <username>: Sets and uses the specified user

    • Error if no username argument provided
    • Saves to ~/.gnlcn/config.json for future use
  2. --user <username>: Uses the specified user

    • Overrides any configured default user
    • Error if invalid format (must be [a-zA-Z0-9]+)
  3. --user (no argument): Falls back to configured user

    • Warning message displayed
    • Error if no configured user exists
  4. No user option: Uses configured default user

    • Error if no configured user exists

The User and Organization Pattern

Keep your repositories in one root folder, with your own repositories directly in it and each organization's repositories in a folder named after the organization, and gnlcn can tell the copyright holder from where a repository sits:

~/projects/                 the pattern root
  demo-app/                 a user repo, held by the name you define (Jane Doe)
  AcmeCorp/                 an organization folder
    widget/                 an organization repo, held by AcmeCorp
  • A user repo is a repository directly in the root. Its holder is the name given with --define.
  • An organization repo is a repository one folder below the root. Its holder is that folder's name, as it is on disk. The folder name must start with a letter or digit, and may hold letters, digits, spaces, -, _ and ., so folders such as .archive or _old never give a holder: -p, -r:pattern-name and -r:pattern-kind refuse a repository in them. The listing's Pattern line and -r:pattern go by position only, so they still say true there.
  • Anything else, two folders below the root, the root itself, or a folder elsewhere, is outside the pattern.
  • The repository is the top folder of the git repository you are in (git rev-parse --show-toplevel), so the pattern works from any folder inside it. Outside a git repository, it is the current folder.
  • Paths are compared the way the system does: without case on Windows, with case elsewhere, and with or without a trailing separator.

Define the Pattern

gnlcn --define ~/projects "Jane Doe"
# Output: Pattern set: '/home/jane/projects', user repos named 'Jane Doe', in /home/jane/.gnlcn/config.json

--define takes exactly two values: an existing folder, saved resolved and absolute, and a name, checked as --user checks it. It is saved apart from the default user, which it leaves as it is. Running it again replaces the pattern.

On Windows, write the root in Windows form, and leave off a trailing backslash inside quotes ("C:\projects", not "C:\projects\", where \" would escape the quote):

gnlcn --define "C:\projects" "Jane Doe"

WSL and Windows each keep their own ~/.gnlcn, so define the root once in each, in that system's form of the path (for example /mnt/c/projects in WSL and C:\projects in Windows).

Write a License With the Pattern's Holder

cd ~/projects/demo-app
gnlcn mit -p
# Output: ✓ Created LICENSE with MIT License
#           Copyright (c) 2026 Jane Doe

cd ~/projects/AcmeCorp/widget
gnlcn mit -p
# Output: ✓ Created LICENSE with MIT License
#           Copyright (c) 2026 AcmeCorp

--year and --output work as they do without -p. With no pattern defined, or in a repository outside it, -p writes nothing, says why, and exits with code 1. -p cannot be used with --user.

Read a License File

gnlcn -r reads LICENSE in the current folder (or the file -o names) and prints one value per line, with no other text:

Repo: demo-app
Pattern: 'true'
Pattern Path: '/home/jane/projects'
License: MIT License
Year: 2026
User: Jane Doe
  • Pattern and Pattern Path appear only when a pattern is defined. Pattern is 'true' for a user repo or an organization repo.
  • License is named offline from the file's first lines, with the names --list shows, or unknown.
  • Year and User come from the first copyright line with a four-digit year (or a range such as 2024-2026), such as Copyright (c) 2026 Jane Doe. The license text's own notice, such as the Free Software Foundation's at the top of the GPL, is skipped. With no such line, both are left empty.

A qualifier prints the bare value only: gnlcn -r:<qualifier> or gnlcn --read:<qualifier>, with the qualifier in any case.

Qualifier Prints Needs LICENSE
repo The repository's folder name No
pattern true or false; false when no pattern is defined No
pattern-path The pattern root No
license The license name, or unknown Yes
year The copyright year Yes
user The holder the file names Yes
pattern-name The holder the pattern gives this repository No
pattern-kind user or organization No

pattern-name and pattern-kind are not in the full listing. Comparing gnlcn -r:user with gnlcn -r:pattern-name tells whether a LICENSE names the holder the pattern expects:

cd ~/projects/AcmeCorp/widget
gnlcn -r:user          # Acme Corp Inc
gnlcn -r:pattern-name  # AcmeCorp
gnlcn -r:pattern-kind  # organization

When a value cannot be given, a qualifier prints nothing on stdout, says why on stderr, and exits with code 1: pattern-path, pattern-name and pattern-kind with no pattern defined, pattern-name and pattern-kind outside the pattern or in an organization folder whose name cannot be a holder, and year and user with no copyright line.

Exit Codes

Code Meaning
0 Done
1 An error, said on stderr: no LICENSE, an unknown qualifier, no pattern, outside the pattern, a folder name that cannot be a holder, or a bad argument

GNLCN_HOME

When the environment variable GNLCN_HOME is set and not empty, gnlcn uses that folder in place of ~/.gnlcn, so a test or a script can keep a configuration of its own:

GNLCN_HOME=/tmp/gnlcn-test gnlcn --define ~/projects "Jane Doe"

Examples

First-time Setup

# Set your default username
gnlcn --config-user JohnDoe
# Output: Default user set to 'JohnDoe' in ~/.gnlcn/config.json

# Now generate licenses without -u
gnlcn mit
# Output: ✓ Created LICENSE with MIT License
#         Copyright (c) 2026 JohnDoe

Quick License Generation

# Using default user
gnlcn apache-2.0
gnlcn gpl-3.0
gnlcn bsd-3-clause

Project with Different Owner

# Override for a specific project
gnlcn mit -u AcmeCorp -y 2024

Check Available Licenses

gnlcn -l

Configuration

Configuration is stored in ~/.gnlcn/config.json (or in $GNLCN_HOME/config.json when GNLCN_HOME is set):

{
  "defaultUser": "JohnDoe",
  "pattern": {
    "path": "/home/jane/projects",
    "name": "Jane Doe"
  }
}

Supported Licenses

The tool supports all licenses available through GitHub's License API:

  • MIT
  • Apache-2.0
  • GPL-3.0
  • BSD-3-Clause
  • BSD-2-Clause
  • ISC
  • MPL-2.0
  • LGPL-3.0
  • Unlicense
  • CC0-1.0
  • And more...

License Aliases

For convenience, you can use common aliases:

Alias License
mit MIT License
apache, apache2 Apache License 2.0
gpl, gpl3 GNU GPL v3.0
bsd, bsd3 BSD 3-Clause
bsd2 BSD 2-Clause
isc ISC License
mpl, mpl2 Mozilla Public License 2.0
lgpl, lgpl3 GNU LGPL v3.0
unlicense The Unlicense
cc0 CC0 1.0 Universal

Development

Build

npm run build

Test

npm test

Run Locally

npm run dev -- mit -u TestUser

Error Handling

The tool provides helpful error messages:

# Missing required argument
$ gnlcn --config-user
Error: The --config-user option requires a username argument.
Usage: gnlcn --config-user <username>
Example: gnlcn --config-user JohnDoe

# Invalid year format
$ gnlcn mit -u JohnDoe -y 20
Error: Invalid year format: '20'. Year must be exactly 4 digits (e.g., 2026).

# License not found
$ gnlcn nonexistent -u JohnDoe
Error: License 'nonexistent' not found. Use --list to see available licenses.

Future Variations

This tool may be extended as:

  • VS Code Extension: Generate licenses directly from the command palette

License

MIT License - see LICENSE for details.

About

A command-line tool that fetches common open source licenses and generates LICENSE files for your projects.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages