-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (55 loc) · 1.2 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
70
package main
import (
"flag"
"fmt"
"os"
"github.com/gavsidhu/templ8/cmd"
"github.com/gavsidhu/templ8/pkg"
)
var (
Version string
Build string
)
func main() {
flag.Usage = func() {
fmt.Fprint(os.Stderr, fmt.Sprint(usage))
}
if len(os.Args) < 2 {
usageAndExit("")
}
var command *pkg.Command
switch os.Args[1] {
case "version":
command = cmd.NewVersionCommand()
case "add":
command = cmd.NewAddCommand()
case "paste":
command = cmd.NewPasteCommand()
case "list":
command = cmd.NewListCommand()
case "delete":
command = cmd.NewDeleteCommand()
default:
usageAndExit(fmt.Sprintf("templ8: '%s' is not a templ8 command.\n", os.Args[1]))
}
command.Init(os.Args[2:])
command.Run()
}
func usageAndExit(msg string) {
if msg != "" {
fmt.Fprint(os.Stderr, msg)
fmt.Fprintf(os.Stderr, "\n")
}
flag.Usage()
os.Exit((0))
}
var usage = `Usage: templ8 command [options]
A simple tool to generate and manage custom templates
Options:
Commands:
add Adds a template to the collection from a local file
paste Pastes the specified template into the current directory
list Lists all stored templates
delete Removes a stored template
version Prints version info to console
`