All Projects → subchen → frep

subchen / frep

Licence: Apache-2.0 license
Generate file using template from environment, arguments, json/yaml/toml config files

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Makefile
30231 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to frep

jquery-smarty
jQuery Smarty Plugin (jQSmarty) is a port of the Smarty Templating Engine to Javascript/jQuery, offering a familiar client-side templating solution
Stars: ✭ 18 (-86.67%)
Mutual labels:  template-engine
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (-85.19%)
Mutual labels:  replace-text
templatel
Jinja inspired template language for Emacs Lisp
Stars: ✭ 46 (-65.93%)
Mutual labels:  template-engine
nornj
More exciting JS/JSX based on Template Engine, support control flow tags, custom directives, two-way binding, filters and custom operators.
Stars: ✭ 97 (-28.15%)
Mutual labels:  template-engine
modulor-html
Missing template engine for Web Components
Stars: ✭ 36 (-73.33%)
Mutual labels:  template-engine
babl
JSON templating on steroids
Stars: ✭ 29 (-78.52%)
Mutual labels:  template-engine
escapevelocity
A subset reimplementation of Apache Velocity with a much simpler API.
Stars: ✭ 28 (-79.26%)
Mutual labels:  template-engine
morestachio
Lightweight, powerful, flavorful, template engine.
Stars: ✭ 45 (-66.67%)
Mutual labels:  template-engine
esh
Simple templating engine based on shell.
Stars: ✭ 165 (+22.22%)
Mutual labels:  template-engine
carbone
Fast and simple report generator, from JSON to pdf, xslx, docx, odt...
Stars: ✭ 810 (+500%)
Mutual labels:  template-engine
replace
Streaming text replacement for Go
Stars: ✭ 50 (-62.96%)
Mutual labels:  replace-text
HTML-templating-with-Google-Apps-Script
Use data from your spreadsheets to build a webpage or a client-side app ✨
Stars: ✭ 55 (-59.26%)
Mutual labels:  template-engine
Fuga-Framework
Web Framework for Java
Stars: ✭ 15 (-88.89%)
Mutual labels:  template-engine
liquid.cr
Kind of liquid template engine for Crystal [WIP]
Stars: ✭ 64 (-52.59%)
Mutual labels:  template-engine
te4j
Fast and easy template engine
Stars: ✭ 20 (-85.19%)
Mutual labels:  template-engine
ultron-ele
The world’s fastest LMS engine based on Gatsby -- Deliver knowledge with fun!
Stars: ✭ 27 (-80%)
Mutual labels:  template-engine
pypugjs
PugJS syntax adapter for Django, Jinja2 and Mako templates
Stars: ✭ 237 (+75.56%)
Mutual labels:  template-engine
tenjin
📝 A template engine.
Stars: ✭ 15 (-88.89%)
Mutual labels:  template-engine
opentbs
With OpenTBS you can merge OpenOffice - LibreOffice and Ms Office documents with PHP using the TinyButStrong template engine. Simple use OpenOffice - LibreOffice or Ms Office to edit your templates : DOCX, XLSX, PPTX, ODT, OSD, ODP and other formats. That is the Natural Template philosophy.
Stars: ✭ 48 (-64.44%)
Mutual labels:  template-engine
gender-render
Template-system and proof-of-concept for rendering gender-neutral text-, email- and RPG-text-templates with the correct pronouns of all people involved.
Stars: ✭ 21 (-84.44%)
Mutual labels:  template-engine

Build Status License

frep

Generate file using template from environment, arguments, json/yaml/toml config files.

NAME:
   frep - Generate file using template

USAGE:
   frep [options] input-file[:output-file] ...

VERSION:
   1.3.x

AUTHORS:
   Guoqiang Chen <[email protected]>

OPTIONS:
   -e, --env name=value    set variable name=value, can be passed multiple times
       --json jsonstring   load variables from json object string
       --load file         load variables from json/yaml/toml file
       --no-sys-env        exclude system environments, default false
       --overwrite         overwrite if destination file exists
       --dryrun            just output result to console instead of file
       --strict            exit on any error during template processing
       --delims value      template tag delimiters (default: {{:}})
       --missing           handling of missing vars, one of: default/invalid, zero, error (default: default)
       --help              print this usage
       --version           print version information

EXAMPLES:
   frep nginx.conf.in -e webroot=/usr/share/nginx/html -e port=8080
   frep nginx.conf.in:/etc/nginx.conf -e webroot=/usr/share/nginx/html -e port=8080
   frep nginx.conf.in --json '{"webroot": "/usr/share/nginx/html", "port": 8080}'
   frep nginx.conf.in --load config.json --overwrite
   echo "{{ .Env.PATH }}"  | frep -

Downloads

v1.3.13 Release: https://github.com/subchen/frep/releases/tag/v1.3.13

  • Linux

    curl -fSL https://github.com/subchen/frep/releases/download/v1.3.13/frep-1.3.13-linux-amd64 -o /usr/local/bin/frep
    chmod +x /usr/local/bin/frep
    
    # centos / redhat
    yum install https://github.com/subchen/frep/releases/download/v1.3.13/frep-1.3.13-204.x86_64.rpm
    
    # ubuntu
    curl -fSL https://github.com/subchen/frep/releases/download/v1.3.13/frep_1.3.13-204_amd64.deb -o frep_1.3.13-204_amd64.deb
    dpkg -i frep_1.3.13-204_amd64.deb
    
  • macOS

    brew install subchen/tap/frep
    
  • Windows

    wget https://github.com/subchen/frep/releases/download/v1.3.13/frep-1.3.13-windows-amd64.exe
    

Docker

You can run frep using docker container

docker run -it --rm subchen/frep --help

Examples

Load template variables

  • Load from environment

    export webroot=/usr/share/nginx/html
    export port=8080
    frep nginx.conf.in
    
  • Load from arguments

    frep nginx.conf.in -e webroot=/usr/share/nginx/html -e port=8080
    
  • Load from JSON String

    frep nginx.conf.in --json '{"webroot": "/usr/share/nginx/html", "port": 8080}'
    
  • Load from JSON file

    cat > config.json << EOF
    {
      "webroot": "/usr/share/nginx/html",
      "port": 8080,
      "servers": [
        "127.0.0.1:8081",
        "127.0.0.1:8082"
      ]
    }
    EOF
    
    frep nginx.conf.in --load config.json
    
  • Load from YAML file

    cat > config.yaml << EOF
    webroot: /usr/share/nginx/html
    port: 8080
    servers:
      - 127.0.0.1:8081
      - 127.0.0.1:8082
    EOF
    
    frep nginx.conf.in --load config.yaml
    
  • Load from TOML file

    cat > config.toml << EOF
    webroot = /usr/share/nginx/html
    port = 8080
    servers = [
       "127.0.0.1:8081",
       "127.0.0.1:8082"
    ]
    EOF
    
    frep nginx.conf.in --load config.toml
    

Input/Output

  • Input from file

    // input file: nginx.conf
    frep nginx.conf.in
    
  • Input from console(stdin)

    // input from stdin pipe
    echo "{{ .Env.PATH }}" | frep -
    
  • Output to default file (Removed last file ext)

    // output file: nginx.conf
    frep nginx.conf.in --overwrite
    
  • Output to the specified file

    // output file: /etc/nginx.conf
    frep nginx.conf.in:/etc/nginx.conf --overwrite -e port=8080
    
  • Output to console(stdout)

    frep nginx.conf.in --dryrun
    frep nginx.conf.in:-
    
  • Output multiple files

    frep nginx.conf.in redis.conf.in ...
    

Template

Templates use Golang text/template.

You can access environment variables within a template

Env.PATH = {{ .Env.PATH }}

If your template file uses {{ and }} as part of it's syntax, you can change the template escape characters using the --delims.

frep --delims "<%:%>" ...

There are some built-in functions as well: Masterminds/sprig v2.22.0

More funcs added:

  • toJson
  • toYaml
  • toToml
  • toBool
  • fileSize
  • fileLastModified
  • fileGetBytes
  • fileGetString
  • fileExists
  • include
  • countRune
  • pipeline compatible regex functions from sprig
    • reReplaceAll
    • reReplaceAllLiteral
    • reSplit
  • awsSecret
  • awsParameterStore

Sample of nginx.conf.in

server {
    listen {{ .port }} default_server;

    root {{ .webroot | default "/usr/share/nginx/html" }};
    index index.html index.htm;

    location /api {
        {{ include "shared/log.nginx" | indent 8 | trim }}
        proxy_pass http://backend;
    }
}

upstream backend {
    ip_hash;
{{- range .servers }}
    server {{.}};
{{- end }}
}

Sample using secrets, first of all take into account that in order to use the secret functionality you need to have a proper AWS configuration in place and permissions enough to read secrets from AWS Secrets Manager. More details of how to configure AWSCLI can be found at https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

Once you have all the requirements just create a template like this one:

# application.conf
mysql_host: {{ .mysql_host }}
mysql_user: {{ .mysql_user }}
mysql_pass: {{ awsSecret "application/mysql/password" }}

In above example mysql_host and mysql_user will be filled as usual by using frep config file or environment variables but mysql_pass will be fetch straight from AWS Secrets Manager by looking at secret name application/mysql/password

If you have multiple items in a single secret you can retrieve an specific key by specifying the key you want in template, for example:

# application.conf
mysql_host: {{ .mysql_host }}
mysql_user: {{ .mysql_user }}
mysql_pass: {{ awsSecret "application/mysql/password" }}

external_api_client: {{ awsSecret "application/external_api" "client_id" }}
external_api_secret: {{ awsSecret "application/external_api" "secret_key" }}

Sample using AWS Parameter Store, first of all take into account that in order to use the ssm functionality you need to have a proper AWS configuration in place and permissions enough to read parameters from AWS Parameter Store. More details of how to configure AWSCLI can be found at https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

Once you have all the requirements just create a template like this one:

# application.conf
mysql_host: {{ .mysql_host }}
mysql_user: {{ .mysql_user }}
mysql_pass: {{ awsSecret "application/mysql/password" }}
mysql_dns: {{ awsParameterStore "application/mysql/dns" }}

In above example mysql_dns will be filled as usual by using frep config file or environment variables but mysql_pass will be fetch straight from AWS Parameter Store by looking at application/mysql/dns

SSM Limitation: You can get parameter from ParameterStore just in textplain.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].