noccylabs/license

$ git tag


$ git branch
* master

License: OSS license helper

License helps you with two things:

  1. Installing a matching LICENSE in the project root.
  2. Installing (or updating) header blocks in all source files. (TBI)

Install a LICENSE (Works)

Select a license, either by using the license field in your composer.json or by passing it as --license or -l to the license command:

$ license install
Guessed license as GPL-3.0.
Installing license to LICENSE...Ok
$ license install --license GPL-2.0
Installing license to LICENSE...Ok
$

Supported licenses (Works)

$ license list-licenses
Available licenses:
 - ARTISTIC
 - BSD
 - GPL-2.0
 - GPL-3.0
 - LGPL-2.0
 - LGPL-3.0
 - QPL-1.0
$
$ license headers --dir src --files php
Using GPL-3.0 from composer.json
Finding files...
Adding GPL-3.0 header to files
  src/foo.php: ok
  src/bar.php: ok
$

php in above command is the name of a definition group in the configuration, including a file pattern (*.php) and where/how/what to add.

  1. Open file
  2. Parse to tokens
  3. Go over tokens until first comment or doccomment, or first non-whitespace tag
  4. If no license comment, replace or insert whitespace at location
  5. Parse tokens back to php
  6. Make a backup (optional)
  7. Write file

Find license block by:

  1. Break license and comment into lines
  2. Trim all lines of * and spaces
  3. Compare lines, break true if we find two matching lines (one in each list)
  4. Break false