giter8 alternative in Go

Overview

go-giter8

Go

go-giter8 implements a simple library capable of handling giter8 templates.

Using as library

  1. Add to go.mod
module github.com/yourusername/yourproject

go 1.16

require github.com/Gympass/go-giter8 v0.2.0
  1. Use props to parse default.properties:
package foo

import (
	"io"
	"os"

	"github.com/Gympass/go-giter8/props"
)

func parseProperties() props.Pairs {
	f, _ := os.Open("/path/to/your/default.properties")
	data, _ := io.ReadAll(f)
	properties, err := props.ParseProperties(string(data))
	if err != nil {
		panic(err)
    }
    return properties
}
  1. Use parsed properties in a template
package foo

import (
	"io"
	"os"

	"github.com/Gympass/go-giter8/lexer"
	"github.com/Gympass/go-giter8/props"
	"github.com/Gympass/go-giter8/render"
)

func parseProperties() props.Pairs { /* ... */ }

func executeTemplate(path string) (string, error) {
	f, _ := os.Open("/path/to/template/file")
	data, _ := io.ReadAll(f)
	parsed, err := lexer.Tokenize(string(data))
	if err != nil {
		return "", err
	}
	e := render.NewExecutor(parseProperties())
	return e.Exec(parsed)
}

Using as command line

Alternatively, you can use the gg8 CLI to download and execute a template:

$ gg8 Gympass/test.g8 test
Clonning https://github.com/Gympass/test.g8.git...
Executing template:

name [Test project]: <return>
otherValue [Pizza]: <return>
Processing templates... OK

$   

One can also provide all options through command-line parameters:

$ gg8 Gympass/test.g8 test -- name="A name" otherValue="othervalue"
Clonning https://github.com/Gympass/test.g8.git...
Executing template:
name: A name 
otherValue: othervalue

Processing templates... OK

License

MIT License

Copyright (c) 2021 Victor Gama

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Issues
  • [PRT-94] Allow properties used in conditionals to be absent

    [PRT-94] Allow properties used in conditionals to be absent

    This relaxes property checking to allow absent properties to be checked for their presence. This also fixes an inconsistency that prevented properties containing dashes (-) from being used in conditional expressions.

    opened by heyvito 0
  • [BUG] Conditional nodes leaking to parent scope [PRT-84]

    [BUG] Conditional nodes leaking to parent scope [PRT-84]

    Considering the following input:

    $if(parent.truthy)$
    Parent OK
    $if(child.truthy)$
    Child OK
    $endif$
    $endif$
    

    The parsed AST becomes:

    Conditional
       Expression: parent.truthy
       Then:
        - Literal(Parent OK)
       Else: nil
       ElseIf: nil
    Conditional
       Expression: child.truthy
       Then:
        - Literal(Child OK)
       Else: nil
       ElseIf: nil
    

    When the following is expected, instead:

    Conditional
       Expression: parent.truthy
       Then:
        - Literal(Parent OK)
        - Conditional
          Expression: child.truthy
          Then:
           - Literal(Child OK)
          Else: nil
          ElseIf: nil
       Else: nil
       ElseIf: nil
    
    bug 
    opened by heyvito 0
  • [PRT-80] feat(render): Add support to verbatim prop

    [PRT-80] feat(render): Add support to verbatim prop

    This adds support to the verbatim property, allowing files and patterns to be ignored from the parsing and render process, making them be copied as-is.

    opened by heyvito 0
  • feat(fs): Implement conditional support to FS items

    feat(fs): Implement conditional support to FS items

    This implements support to conditional file items. For instance, considering the following directory structure:

    ├── directory
    │   └── file.txt
    └── $if(foo.truthy)$bar$end$
        └── otherfile.txt
    

    And props as:

    foo = n
    

    Rendering this directory template will yield the following structure:

    └── directory
        └── file.txt
    

    And having foo defined as any truthy value (such as yes, y, or true) yields the following structure:

    ├── directory
    │   └── file.txt
    └── bar
        └── otherfile.txt
    
    opened by heyvito 0
  • feat(conditionals): Implement conditional support

    feat(conditionals): Implement conditional support

    This implements support for conditionals. Conditionals can now be used with a single truthy helper, just like the following example:

    Given a property pair:

    p := pairs.FromMap(map[string]string{"prop_name": "true"})
    

    and a template:

    $if(prop_name.truthy)$
    foo
    $else$
    bar
    $endif$
    

    the following would be rendered:

    foo
    

    truthy checks for the following values in a case-insensitive manner: yes, y, true. All other values are considered as false.

    Known problems

    1. Empty lines are not stripped within a conditional block. For instance, a block with the following characters: $if(foo.truthy)$\nfoo\n$else$\nbar\n$endif$ would be rendered as \nfoo\n in case foo equals true. ~~2. If-elseif-else orders are not respected. One is able to write an if-else-elseif structure and it will be executed as if-elseif-else.~~ Addressed by 4af06ab8d99ee30ea625259f01d8d50c65cfc434
    opened by heyvito 0
Owner
Gympass
Gympass
An alternative syntax to generate YAML (or JSON) from commandline

yo An alternative syntax to generate YAML (or JSON) from commandline. The ultimate commanline YAML (or JSON) generator! ... I'm kidding of course! but

Luca Sepe 10 Feb 2, 2022
🐘 Cross-platform, neofetch alternative for fetching system info.

elefetch ?? Cross-platform, neofetch alternative for fetching system info. Installation go get: go get -u github.com/burntcarrot/elefetch Binaries Bin

Aadhav Vignesh 1 Jan 23, 2022
💾 A visual du(1) alternative for human beings

dux A disk usage analyzer. Like du(1), but displays the results as an interactive treemap. testdata 111B (8 files) (4) ┌testdata/ 111B────────────

Jens Green Olander 1 Jan 15, 2022
archy is an static binary to determine current kernel and machine architecture, with backwards compatible flags to uname, and offers alternative output format of Go runtime (i.e. GOOS, GOARCH).

archy archy is an simple binary to determine current kernel and machine architecture, which wraps uname and alternatively can read from Go runtime std

xargs-dev 3 Mar 18, 2022
:key: Secure alternative to JWT. Authenticated Encrypted API Tokens for Go.

branca branca is a secure alternative to JWT, This implementation is written in pure Go (no cgo dependencies) and implements the branca token specific

Wesley Hill 166 Mar 19, 2022
Concurrent task runner, developer's routine tasks automation toolkit. Simple modern alternative to GNU Make 🧰

taskctl - concurrent task runner, developer's routine tasks automation toolkit Simple modern alternative to GNU Make. taskctl is concurrent task runne

null 184 May 2, 2022
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.

koanf (pronounced conf; a play on the Japanese Koan) is a library for reading configuration from different sources in different formats in Go applicat

Kailash Nadh 981 May 14, 2022
A fast and powerful alternative to grep

sift A fast and powerful open source alternative to grep. Features sift has a slightly different focus than most other grep alternatives. Code search,

Sven Taute 1.5k May 6, 2022
Alternative archiving tool with fast performance for huge numbers of small files

fast-archiver fast-archiver is a command-line tool for archiving directories, and restoring those archives written in [Go](http://golang.org). fast-ar

Replicon Inc. 173 May 5, 2022
Alternative sync library for Go

Alternative sync library for Go. Overview Future - A placeholder object for a value that may not yet exist. Promise - While futures are defined as a t

Eugene R. 47 May 10, 2022
Glue - Robust Go and Javascript Socket Library (Alternative to Socket.io)

Glue - Robust Go and Javascript Socket Library Glue is a real-time bidirectional socket library. It is a clean, robust and efficient alternative to so

DesertBit 401 May 10, 2022
Glue - Robust Go and Javascript Socket Library (Alternative to Socket.io)

Glue - Robust Go and Javascript Socket Library Glue is a real-time bidirectional socket library. It is a clean, robust and efficient alternative to so

DesertBit 402 May 15, 2022
An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

Edwin 460 Apr 14, 2022
An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

Edwin 11 May 10, 2021
Germanium is an alternative to Carbon and Silicon implemented in Go.

Germanium is an alternative to Carbon and Silicon implemented in Go. Germanium can work without browser and internet like Silicon.

Masaya Watanabe 179 Apr 19, 2022
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Mesh RPC MeshRPC provides automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio. In a nutshell

AstraNet Toolkit 68 Apr 19, 2022
Lightweight selfhosted Firefox Send alternative without public upload

Gokapi Available for: Bare Metal Docker About Gokapi is a lightweight server to share files, which expire after a set amount of downloads or days. It

Marc Ole Bulling 274 May 12, 2022
Disk Usage/Free Utility - a better 'df' alternative

duf Disk Usage/Free Utility (Linux, BSD, macOS & Windows) Features User-friendly, colorful output Adjusts to your terminal's width Sort the results ac

Christian Muehlhaeuser 8.5k May 14, 2022
One of the fastest alternative JSON parser for Go that does not require schema

Alternative JSON parser for Go (10x times faster standard library) It does not require you to know the structure of the payload (eg. create structs),

Leonid Bugaev 4.5k May 19, 2022
A task runner / simpler Make alternative written in Go

Task Task is a task runner / build tool that aims to be simpler and easier to use than, for example, GNU Make. See taskfile.dev for the documentation.

Task 5.1k May 14, 2022
LinkPage is a FOSS self-hosted alternative to link listing websites such as LinkTree and Campsite.bio

LinkPage LinkPage is a FOSS self-hosted alternative to link listing websites such as LinkTree and Campsite.bio Features Self hostable and open source

Rohan Verma 43 Apr 18, 2022
Mouthful is a self-hosted alternative to Disqus.

Mouthful is a lightweight commenting server written in GO and Preact. It's a self hosted alternative

Viktoras 725 May 10, 2022
Yet another codemod alternative

rnm Yet another codemod alternative. Replace all occurrences of a name to another name in your code! Features Support for different case styles See rn

Yota Toyama 19 Mar 3, 2022
An alternative syntax to generate YAML (or JSON) from commandline

yo An alternative syntax to generate YAML (or JSON) from commandline. The ultimate commanline YAML (or JSON) generator! ... I'm kidding of course! but

Luca Sepe 10 Feb 2, 2022
Fork of Go stdlib's net/http that works with alternative TLS libraries like refraction-networking/utls.

github.com/ooni/oohttp This repository contains a fork of Go's standard library net/http package including patches to allow using this HTTP code with

Open Observatory of Network Interference (OONI) 16 Apr 30, 2022
Focalboard is an open source, self-hosted alternative to Trello, Notion, and Asana.

Focalboard Like what you see? ?? Give us a GitHub Star! ⭐ Focalboard is an open source, self-hosted alternative to Trello, Notion, and Asana. It helps

Mattermost 11k May 18, 2022
SigNoz helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc. 🔥 🖥. 👉 Open source Application Performance Monitoring (APM) & Observability tool

Monitor your applications and troubleshoot problems in your deployed applications, an open-source alternative to DataDog, New Relic, etc. Documentatio

SigNoz 4.7k Sep 24, 2021
Chadburn is a scheduler alternative to cron, built on Go and designed for Docker environments.

Chadburn - a job scheduler Chadburn is a modern and low footprint job scheduler for docker environments, written in Go. Chadburn aims to be a replacem

PremoWeb Internet Services 23 May 16, 2022