Docs: Easygen usage - go-easygen/easygen GitHub Wiki
The easygen usage
Command line
Check here for more on using easygen the command line tool.
The library
The easygen is a library as well as a command line tools. Not only it is super easy to use, it is super easy to extend as well.
The restructured easygen can now be a building block that people can easily extend, any extra functionalities, or extra feature that it depends on, or any external dependencies are now moved out to sub modules. Thus the library users can now pick and choose exactly what they want from the library.
- The egVar package example shows how to add the variable name manipulation on top of the default library.
- The egCal package example shows how to add the variable name manipulation and generic calculation functionalities, together with the default functions, all at the same time.
To put them all together, check out the easygen's main.go:
> cmd/easygen/main.go
package main
import (
"flag"
"os"
"github.com/go-easygen/easygen"
"github.com/go-easygen/easygen/egCal"
"github.com/go-easygen/easygen/egVar"
)
//go:generate sh -v easygen.gen.sh
////////////////////////////////////////////////////////////////////////////
// Main
func main() {
flag.Usage = Usage
flag.Parse()
// One mandatory non-flag arguments
if flag.NArg() < 1 {
Usage()
}
tmpl0 := easygen.NewTemplate().Customize()
tmpl := tmpl0.Funcs(easygen.FuncDefs()).
Funcs(egVar.FuncDefs()).Funcs(egCal.FuncDefs())
args := flag.Args()
if len(easygen.Opts.TemplateStr) > 0 {
easygen.Process0(tmpl, os.Stdout, easygen.Opts.TemplateStr, args...)
} else {
easygen.Process(tmpl, os.Stdout, args...)
}
}
It has been as simple as this up until version 3. I.e., it's quite simple to make use of easygen as a package.