codegen

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

codegen

A small tool to automatically generate code starting from one or more template fil(s), and a csv file.

Contents

Installation

go install github.com/Abathargh/codegen/cmd/codegen@latest

Binaries are available from the release section.

Get it as a library
# either clone everything and build it
go get github.com/Abathargh/codegen@latest 

How To

This tool is able to substitute data from csv files into template files containing tokens in the #n# format, where n is a number greater or equal to 1. You could also use different separators, '#' is the default one.

If you have a template file called templ.c, and a csv called data.csv like these:

#define test_#1# #2#
test,123
test2,456
test3,testing

You may call codegen like this:

codegen -t templ.c -d data.csv 

This is what will be generated:

#define test_test 123
#define test_test2 456
#define test_test3 testing

Usage

usage: codegen [-h|--help] -t|--template "<value>" [-t|--template "<value>"
               ...] -d|--data "<value>" [-s|--separator "<value>"] [-l|--limit
               <integer>]

               Generates files based on templates and csv tables. Template
               files contain tokens in the #n# format, where n is a number and
               # is the default separator. If the passed csv has n columns, the
               application will be able to substitute tokens with the
               corresponding column values, up to a total of n,for each row of
               the csv file.

Arguments:

  -h  --help       Print help information
  -t  --template   a template to process in order to generate code, it should
                   contain tokens in the #n# format, where n is a number and #
                   is the default separator: e.g. #1# #2#
  -d  --data       a csv file that contains the data to substitute the tokens
                   with
  -s  --separator  the separator to use to identify tokens, defaults to #.
                   Default: #
  -l  --limit      limits the csv substitution up to the first n rows, defaults
                   to 0, meaning no limit is applied. Default: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeGenerator

type CodeGenerator struct {
	// contains filtered or unexported fields
}

func (*CodeGenerator) Generate

func (gen *CodeGenerator) Generate(upTo uint) error

Generate Generates the files with respecte to the passed templates and csv data

func (*CodeGenerator) LoadGenerator

func (gen *CodeGenerator) LoadGenerator(templateFiles []string, dataFile string, separator rune) error

LoadGenerator Initializes a CodeGenerator, loading the template info and data file name. The data file is a csv file, where each row contains one tuple of data to be generated following the template.

Directories

Path Synopsis
cmd
codegen command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL