commit 44046341333e0b1b6c9f28c4c9177abdb7025df0
parent 254722853f24e3f347e1e78adca03ac5f65aabf6
Author: gearsix <gearsix@tuta.io>
Date: Tue, 9 Mar 2021 20:35:41 +0000
finished main(); only accept 1 root template
Diffstat:
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/src/suti.go b/src/suti.go
@@ -6,7 +6,7 @@ import (
)
type Options struct {
- RootPaths []string
+ RootPath string
PartialPaths []string
GlobalDataPaths []string
DataPaths []string
@@ -30,19 +30,18 @@ func init() {
}
func main() {
-
- _ = LoadDataFiles("", options.GlobalDataPaths...)
- _ = LoadDataFiles(options.SortData, options.DataPaths...)
-
- templates := make([]Template, 0)
- for _, r := range options.RootPaths {
- if t, e := LoadTemplateFile(r, options.PartialPaths...); e != nil {
- warn("unable to load templates (%s)", e)
- } else {
- templates = append(templates, t)
- }
+ gd := LoadDataFiles("", options.GlobalDataPaths...)
+ d := LoadDataFiles(options.SortData, options.DataPaths...)
+ sd := GenerateSuperData(options.DataKey, d, gd...)
+
+ if t, e := LoadTemplateFile(options.RootPath, options.PartialPaths...); e != nil {
+ warn("unable to load templates (%s)", e)
+ } else if out, err := ExecuteTemplate(t, sd); err != nil {
+ warn("failed to execute template '%s' (%s)", options.RootPath, err)
+ } else {
+ fmt.Println(out.String())
}
-
+
return
}
@@ -70,8 +69,8 @@ func parseArgs(args []string) (o Options) {
}
// set valid any flags that don't take arguments here
- } else if flag == "r" || flag == "root" {
- o.RootPaths = append(o.RootPaths, arg)
+ } else if (flag == "r" || flag == "root") && len(o.RootPath) == 0 {
+ o.RootPath = arg
} else if flag == "p" || flag == "partial" {
o.PartialPaths = append(o.PartialPaths, arg)
} else if flag == "gd" || flag == "globaldata" {
diff --git a/suti.txt b/suti.txt
@@ -23,9 +23,8 @@ DESCRIPTION
See suti-lib for details.
OPTIONS
- -r path..., -root path...
- path of (multiple) template files to execute against. If a directory is
- passed then all files within that directory will (recursively) be loaded.
+ -r path, -root path
+ path of template file to execute against.
-p path..., -partial path...
path of (multiple) template files that are called upon by at least one