-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (58 loc) · 1.26 KB
/
main.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"embed"
"fmt"
"log"
"os"
"strings"
"github.com/urfave/cli/v2"
)
//TODO: add jobs to templates
//TODO: create -o flag to generate a file
//TODO: add jobs to templates
var (
//go:embed templates/*
templates embed.FS
)
func generate(ctx *cli.Context) error {
file := ctx.Args().Get(0)
template, err := templates.ReadFile(fmt.Sprintf("templates/%s.yaml", file))
if err != nil {
return fmt.Errorf("Template not found")
} else {
fmt.Println(string(template))
return nil
}
}
func list(ctx *cli.Context) error {
dir, _ := templates.ReadDir("templates")
fmt.Println("The following templates are in this binary:")
fmt.Println("-------------------------------------------")
for _, file := range dir {
resource := strings.Split(file.Name(), ".")[0]
fmt.Println(resource)
}
fmt.Println("-------------------------------------------")
return nil
}
func main() {
app := &cli.App{
Commands: []*cli.Command{
{
Name: "make",
Aliases: []string{"m", "mk"},
Usage: "Generates a resource template",
Action: generate,
},
{
Name: "list",
Aliases: []string{"l", "ls"},
Usage: "Lists available templates",
Action: list,
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}