Next: , Up: Writing boilerplate   [Index]


4.1 apply: Write the working boilerplate to source files

After a current working boilerplate has been created, and it looks good in the preview command, it is time to actually put the boilerplate into files. apply is the command that is used to write the current working boilerplate to source code files. When starting a new project, it is used like so:

$ ls
bar.c  foo.c  foo.h  Makefile  qux.c
$ licensing apply *.[ch]
apply: foo.c -> Boilerplate applied.
apply: bar.c -> Boilerplate applied.
apply: qux.c -> Boilerplate applied.
apply: foo.h -> Boilerplate applied.

This example adds the boilerplate to the beginning of the .c and .h files in the current directory.

The apply will fail to operate when the current working boilerplate lacks copyright holders or a license.

When a source file happens to be a script, the boilerplate will appear after the ‘#!’ line. To place the boilerplate after any previously existing boilerplate in the source file, use the --after option. When the commenting-style is not specified with an option (see Common Commenting-style options, it is automatically detected. For example:

$ cat foo.sh
#!/bin/bash
# hello world
echo hello world
$ licensing choose all-permissive shell --quiet
$ licensing copyright Yoyodyne, Inc. 2001 --quiet
$
$ licensing apply foo.sh --after --shell-style --no-backup
apply: foo.sh -> Boilerplate applied.
$ cat foo.sh
#!/bin/bash
# hello world
# Copyright (C) 2001 Yoyodyne, Inc.
# 
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.
echo hello world

This example puts the current working boilerplate after the shell boilerplate in foo.sh.

By default a backup .bak file is created; to prevent this behaviour use the --no-backup option.

The --quiet option prevents the ‘Boilerplate applied.’ messages from being displayed.

Subsequent calls to the apply command are cumulative. If a mistake has been made, it can be removed with the ‘boilerplate --remove’ command.

The apply command uses the preview command to generate the current working boilerplate.


Next: , Up: Writing boilerplate   [Index]