Home

tmpl @5e164b9bb94e60b60c506f239485e5b27b6b338e - refs - log -
-
https://git.jolheiser.com/tmpl.git
Template automation
tmpl / cmd / test.go
- raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cmd

import (
	"os"

	"github.com/urfave/cli/v2"
	"go.jolheiser.com/beaver"
)

var Test = &cli.Command{
	Name:        "test",
	Usage:       "Test if a directory is a valid template",
	Description: "Test whether the current directory is valid for use with tmpl",
	Action:      runTest,
}

func runTest(_ *cli.Context) error {
	var errs []string
	if _, err := os.Lstat("template.toml"); err != nil {
		errs = append(errs, "could not find template.toml")
	}

	fi, err := os.Lstat("template")
	if err != nil {
		errs = append(errs, "no template directory found")
	}
	if err == nil && !fi.IsDir() {
		errs = append(errs, "template path is a file, not a directory")
	}

	if len(errs) > 0 {
		for _, err := range errs {
			beaver.Error(err)
		}
		return nil
	}
	beaver.Info("this is a valid tmpl template")
	return nil
}