Skip to content

Runs ESH (Embedded SHell) Templates using Test Cases embedded as Front Matter

License

Notifications You must be signed in to change notification settings

RobertDeRose/esh-template-check

Repository files navigation

ESH Template Check Pre-Commit Hook

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.

Features

  • 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.

Setup

To use this hook in your repository:

  1. 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

Supported Arguments

  • -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
  • -v
    • Enable verbose output when an error occurs
  • -s=SHELL
    • Override the Shell that ESH will use, by default uses Bash

Supported Front Matter

  • 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

Example 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}"
}

About

Runs ESH (Embedded SHell) Templates using Test Cases embedded as Front Matter

Resources

License

Stars

Watchers

Forks

Packages

No packages published