headroom: License Header Manager

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

So you are tired of managing license headers in your codebase by hand? Then Headroom is the right tool for you! Now you can define your license header as Mustache template, put all the variables (such as author's name, year, etc.) into the YAML config file and Headroom will take care to add such license headers to all your source code files.


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.3.0, 0.1.3.0, 0.2.0.0, 0.2.1.0, 0.2.1.1, 0.2.2.0, 0.2.2.1, 0.3.0.0, 0.3.1.0, 0.3.2.0, 0.4.0.0, 0.4.1.0, 0.4.2.0, 0.4.3.0
Change log CHANGELOG.md
Dependencies aeson (>=1.4.7.0 && <1.5), base (>=4.7 && <5), either (>=5.0.1.1 && <5.1), file-embed (>=0.0.11.2 && <0.1), headroom, lens (>=4.18.1 && <4.19), mustache (>=2.3.1 && <2.4), optparse-applicative (>=0.15.1.0 && <0.16), pcre-heavy (>=1.0.0.2 && <1.1), pcre-light (>=0.4.1.0 && <0.5), rio (>=0.1.14.1 && <0.2), template-haskell (>=2.15.0.0 && <2.16), text (>=1.2.4.0 && <1.3), time (>=1.9.3 && <1.10), validation (>=1.1 && <1.2), yaml (>=0.11.3.0 && <0.12) [details]
License BSD-3-Clause
Copyright Copyright (c) 2019-2020 Vaclav Svejcar
Author Vaclav Svejcar
Maintainer vaclav.svejcar@gmail.com
Category Utils
Home page https://github.com/vaclavsvejcar/headroom
Bug tracker https://github.com/vaclavsvejcar/headroom/issues
Source repo head: git clone https://github.com/vaclavsvejcar/headroom
Uploaded by xwinus at 2020-03-23T18:14:59Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for headroom-0.1.3.0

[back to package description]

So you are tired of managing license headers in your codebase by hand? Then Headroom is the right tool for you! Now you can define your license header as Mustache template, put all the variables (such as author's name, year, etc.) into the YAML config file and Headroom will take care to add such license headers to all your source code files.

Table of Contents

1. Main Features

2. Planned Features

3. Installation

Binary distribution will be available soon, there are also plans to add Headroom to popular package managers.

3.1. From Source Code

Headroom is written in Haskell, so you can install it from source code either using Cabal or Stack.

3.1.1. Using Cabal

  1. install Cabal for your platform
  2. run cabal install headroom
  3. add $HOME/.cabal/bin to your $PATH

3.1.2. Using Stack

  1. install Stack for your platform
  2. run stack install headroom
  3. add $HOME/.local/bin to your $PATH

4. Basic Overview

4.1. Main Concepts

  1. Template files - Template files contains templates in Mustache format, used for rendering license headers. During rendering phase, all variables are replaced by values loaded from YAML configuration file. Each supported source code file has unique template, because license headers may differ for individual programming languages (i.e. different syntax for comments, etc.).
  2. Source Code Files - Headroom automatically discovers individual source code files in configured location and can manage (add/remove/drop) license headers in supported types of source code files.
  3. Variables - are defined in YAML configuration file and these values are used to replace variables present in the template files.

4.2. License Header Detection

Unlike many other tools, Headroom can not only add, but also replace or drop existing license headers in source code files, even if there is already some header not generated by Headroom. This is done by implementing unique detection logic for each individual supported file type, but usually it's expected that the very first block comment is the license header. If you miss support for your favorite file type, please open new issue.

5. Quick Start Guide

Let's demonstrate how to use Headroom in real world example: assume you have small source code repository with following structure and you'd like to setup Headroom for it:

project/
  └── src/
      ├── scala/
      │   ├── Foo.scala
      │   └── Bar.scala
      └── html/
          └── template1.html

5.1. Initializing Headroom

5.1.1. Automatic Initialization

Easiest and fastest way how to initialize Headroom for your project is to use the Init command, which generates all the boilerplate for you. The only drawback is that you can use it only in case that you use any supported open source license for which Headroom contains license header templates:

cd project/
headroom init -l bsd3 -s src/

This command will automatically scan source code directories for supported file types and will generate:

  1. .headroom.yaml configuration file with correctly set path to template files, source codes and will contain dummy values for variables.
  2. headroom-templates/ directory which contains template files for all known file types you use in your project and for open source license you choose.

Now the project structure will be following:

project/
  ├── src/
  │   ├── scala/
  │   │   ├── Foo.scala
  │   │   └── Bar.scala
  │   └── html/
  │       └── template1.html
  ├── headroom-templates/
  │   ├── html.mustache
  │   └── scala.mustache
  └── .headroom.yaml

5.1.2. Manual Initialization

If you for some reason don't want to use the automatic initialization using the steps above, you can either create all the required files (YAML configuration and template files) by hand, or you can use the Generator command to do that in semi-automatic way:

cd project/
headroom gen -c >./.headroom.yaml

mkdir headroom-templates/
cd headroom-templates/

headroom gen -l bsd3:css >./css.mustache
headroom gen -l bsd3:html >./html.mustache
headroom gen -l bsd3:scala >./scala.mustache

After these steps, make sure you set correctly the paths to template files and source code files in the YAML configuration file.

5.2. YAML Configuration File

Headroom's YAML configuration file must be placed in root of your project and called .headroom.yaml. The configuration itself is pretty simple and consists of following keys:

run-mode: add
source-paths:
  - .
template-paths:
  - headroom-templates
variables:
  author: John Smith
  email: john.smith@example.com
  project: My project
  year: '2020'

These settings can be then overriden by corresponding command line optionss. See more details about these settings in command line interface overview section below.

5.3. Running Headroom

Now we're ready to run Headroom:

cd project/
headroom run      # adds license headers to source code files
headroom run -r   # adds or replaces existing license headers
headroom run -d   # drops existing license headers from files

6. Command Line Interface Overview

Headroom provides various commands for different use cases. You can check commands overview by performing following command:

$ headroom --help
headroom v0.1.3.0 :: https://github.com/vaclavsvejcar/headroom

Usage: headroom COMMAND
  manage your source code license headers

Available options:
  -h,--help                Show this help text

Available commands:
  run                      add or replace source code headers
  gen                      generate stub configuration and template files
  init                     initialize current project for Headroom

6.1. Init Command

Init command is used to initialize Headroom for project by generating all the required files (YAML config file and template files). You can display available options by running following command:

$ headroom init --help
Usage: headroom init (-l|--license-type LICENSE_TYPE) (-s|--source-path PATH)
  initialize current project for Headroom

Available options:
  -l,--license-type LICENSE_TYPE
                           type of open source license
  -s,--source-path PATH    path to source code file/directory
  -h,--help                Show this help text

6.2. Run Command

Run command is used to manipulate (add, replace or drop) license headers in source code files. You can display available options by running following command:

$ headroom run --help
Usage: headroom run [-s|--source-path PATH] [-t|--template-path PATH]
                    [-v|--variable KEY=VALUE] ([-r|--replace-headers] |
                    [-d|--drop-headers]) [--debug]
  add or replace source code headers

Available options:
  -s,--source-path PATH    path to source code file/directory
  -t,--template-path PATH  path to header template file/directory
  -v,--variable KEY=VALUE
                           values for template variables
  -r,--replace-headers     force replace existing license headers
  -d,--drop-headers        drop existing license headers only
  --debug                  produce more verbose output
  -h,--help                Show this help text

Note that command line options override options set in the configuration YAML file. Relation between command line options and YAML configuration options is below:

YAML option Command Line Option
run-mode: add (default mode)
run-mode: drop -d, --drop-headers
run-mode: replace -r, --replace-headers
source-paths -s, --source-path
template-paths -t, --template-path

6.3. Generator Command

Generator command is used to generate stubs for license header template and YAML configuration file. You can display available options by running following command:

$ headroom gen --help
Usage: headroom gen [-c|--config-file] [-l|--license name:type]
  generate stub configuration and template files

Available options:
  -c,--config-file         generate stub YAML config file to stdout
  -l,--license name:type   generate template for license and file type
  -h,--help                Show this help text

When using the -l,--license option, you need to select the license type and file type from the list of supported ones listed bellow. For example to generate template for Apache 2.0 license and Haskell file type, you need to use the headroom gen -l apache2:haskell.

6.3.1. Supported License Types

Below is the list of supported open source license types. If you miss support for license you use, feel free to open new issue.

License Used Name
Apache 2.0 apache2
BSD 3-Clause bsd3
GPLv2 gpl2
GPLv3 gpl3
MIT mit

6.3.2. Supported File Types

Below is the list of supported source code file types. If you miss support for programming language you use, feel free to open new issue.

Language Used Name Supported Extensions
CSS css .css
Haskell haskell .hs
HTML html .html, .htm
Java java .java
JavaScript js .js
Scala scala .scala