This pre-commit hook processes esh
templates, renders them with test cases specified
in YAML
front matter, and optionally runs shellcheck
on the generated
files.
- Parses YAML front matter to extract test cases and
shellcheck
arguments. - Preprocesses ESH templates for each test case.
- Runs
shellcheck
with specified arguments, if provided.
To use this hook in your repository:
- Add this repo to your
.pre-commit-config.yaml
:
- repo: https://github.com/RobertDeRose/esh-template-check
rev: v1.0.0
hooks:
- id: esh-template-check
- -k
- Keep the generated output after running. Stores generated output in
esh_template_output
- If you enable keeping the output, it is recommended add the above directory to your
.gitignore
file
- Keep the generated output after running. Stores generated output in
- -v
- Enable verbose output when an error occurs
- -s=SHELL
- Override the Shell that ESH will use, by default uses Bash
- check_args
- This should be a string that will be passed in as the arguments to shellcheck
- test_cases
- This is an array of key/value pairs to be set as variables for the template
#!/bin/bash
<%# --- -%>
<%# check_args: -s bash -%>
<%# test_cases: -%>
<%# - VAR1: one -%>
<%# VAR2: two -%>
<%# - VAR1: a -%>
<%# VAR2: b -%>
<%# - VAR1: 1 -%>
<%# VAR2: 2 -%>
<%# --- -%>
<% if [[ "${VAR1}" =~ ^(one|a)$ ]]; then -%>
<%= "# Generating script for ${VAR2}" %>
hello_world() {
local name
<% if [[ "${VAR1}" == "one" ]]; then %>
name="Rob"
<% elif [[ "${VAR1}" == "a" ]]; then %>
name="Bob"
<% fi %>
echo "Hello ${name} you got ${VAR2}"
}