GithubHelp home page GithubHelp logo

marcelocarlos / datasubst Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 35 KB

A simple go template based tool that supports JSON, YAML and environment variables as data sources.

License: Apache License 2.0

Go 96.07% Dockerfile 3.93%
yaml json environment-variables templating gotemplate envsubst datasubst

datasubst's Introduction

datasubst

A simple go template based tool that supports JSON, YAML and environment variables as data sources.

This tool has been written as an alternative to envsubst in order to support additional data source formats, such as YAML and JSON files. Since it is powered by go template, built-in functions, loops, conditionals and more can be used for extra flexibility.

Installation

On macOS or Linux, a Homebrew formula is available:

brew tap marcelocarlos/tap
brew install datasubst

Alternatively, you can install a development version using:

go get github.com/marcelocarlos/datasubst

If you don't want to install it, you can run datasubst via Docker instead:

docker run --rm ghcr.io/marcelocarlos/datasubst:v0

GitHub Action

There is also a setup-datasubst action available so you can use datasubst in your GitHub Actions workflow. To use it, just add the following step in you workflow:

- name: Setup datasubst
  uses: marcelocarlos/setup-datasubst@v1
  with:
    version: v0.7.0

Usage

# Using JSON as data source
datasubst --json-data examples/basic-data.json -i examples/basic-input.txt
# Using YAML as data source
datasubst --yaml-data examples/basic-data.yaml -i examples/basic-input.txt
# Using environment variables as data source
TEST1="hello" TEST2="world" datasubst --input examples/basic-input-env.txt --env-data

# Using stdin - JSON
echo "v1: {{ .key1 }}" | datasubst --json-data examples/basic-data.json
# Using stdin - YAML
echo "v3: {{ .key2.first.key3 }}" | datasubst --yaml-data examples/basic-data.yaml
# Using stdin - env
echo "{{ .TEST1 }} {{ .TEST2 }}" | TEST1="hello" TEST2="world" datasubst --env-data

# Specifying JSON subtrees to use (available for JSON and YAML)
echo "{{ .first.key3 }}" | datasubst --json-data examples/basic-data.json --subtree .key2
# Specifying YAML subtrees to use (available for JSON and YAML)
datasubst --json-data examples/basic-data.json --subtree .key2 -i examples/basic-input-subtree.txt

# Using additional options, such -s (strict mode) and -d (change delimiters)
echo "(( .TEST ))" | TEST="hi" datasubst --env-data -d '((:))' -s

See examples for more.

Build from source

go build -ldflags=-X=main.Version=$(git describe --tags)

datasubst's People

Contributors

dependabot[bot] avatar marcelocarlos avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

leenie

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.