jlongster/nunjucks — pull request #134 by arcanis (2013-10-03 15:31:04+00:00)
Title: Better option handling

Hi,

This pull request gives a better option handling to nunjucks while keeping backward compatibility.

Merging this would allow you to give more flexibility to the tool by giving your user a nice way to select which folders / files should be built.

First, the new usage :

```
/home/vagrant/nunjucks/bin/precompile [-f|--force] [-a|--filters ] [-i|--include ] [-x|--exclude ]

Options:
--help Display this help message
--force Force compilation to continue on error
--filters Give the compiler a comma-delimited list of asynchronous filters,
required for correctly generating code
--include Include a file or folder which match the regex but would otherwise
be excluded. You can use this flag multiple times
[default: ["\\.html$","\\.jinja$"]]
--exclude Exclude a file or folder which match the regex but would otherwise
be included. You can use this flag multiple times [default: []]
```

Next, few remarks :

- I added `optimist` into package dependencies. It's a great lightweight library automatically parsing command line arguments.
- Every parameter is alias'd on one or more short options (help = ? = h, force = f, filters = a, include = i, exclude = x)
- The include list is used to know which templates should be compiled (regex matching, default html/jinja extensions).
- The exclude list is used to know which folders should be excluded (regex matching too, default empty).

Finally, the "could-be-better" part :

- Once a file is included, it will not be excluded even if a later `exclude` option should have this effect

bin/precompile -i \.txt$ -x \.txt$ # Every txt file will be included

- Once a folder is excluded, it will not be included even if a later `include` option should have this effect

bin/precompile -x ^foo/ -i ^foo/ # The 'foo' folder will not be processed