Giter VIP home page Giter VIP logo

frep's Introduction

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.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
       --overwrite         overwrite if destination file exists
       --dryrun            just output result to console instead of file
       --delims value      template tag delimiters (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.3 Release: https://github.com/subchen/frep/releases/tag/v1.3.3

  • Linux

    curl -fSL https://github.com/subchen/frep/releases/download/v1.3.3/frep-1.3.3-linux-amd64 -o /usr/local/bin/frep
    chmod +x /usr/local/bin/frep
    
  • macOS

    brew install subchen/tap/frep
    
  • Windows

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

Docker

You can run frep using docker container

docker run -it --rm subchen/frep:1.3.3 --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.14.1

More funcs added:

  • toJson
  • toYaml
  • toToml
  • fileSize
  • fileLastModified
  • fileGetBytes
  • fileGetString

Sample of nginx.conf.in

server {
    listen {{.port}} default_server;

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

    location /api {
        access_log off;
        proxy_pass http://backend;
    }
}

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

frep's People

Contributors

subchen avatar kevpie avatar

Watchers

Imran Ansari avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.