Newer
Older
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
package cmd
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"time"
cli "github.com/spf13/cobra"
"github.com/tmrts/cookie/pkg/config"
"github.com/tmrts/cookie/pkg/template"
"github.com/tmrts/cookie/pkg/util/osutil"
)
var Use = &cli.Command{
Use: "use",
Short: "Executes a project template",
Run: func(_ *cli.Command, args []string) {
tmpl, err := template.Get(args[0])
if err != nil {
panic(err)
}
metadata := template.Metadata{
Name: "test-project-1",
Author: "test-author",
Email: "test@mail.com",
Date: time.Now().Format("Mon Jan 2 2006 15:04:05"),
Version: "0.0.1",
}
err = tmpl.Execute(args[1], metadata)
if err != nil {
panic(err)
}
/*
*err := tmpl.Persist()
*if err != nil {
* panic(err)
*}
*/
},
}
var Save = &cli.Command{
Use: "save",
Short: "Saves a project template to template registry",
Run: func(_ *cli.Command, args []string) {
templateName, sourceDir := args[0], args[1]
targetDir := filepath.Join(config.TemplateDirPath, templateName)
switch err := osutil.FileExists(targetDir); {
case !os.IsNotExist(err):
// Template Already Exists Ask If Should be Replaced
panic(err)
}
if _, err := exec.Command("sh", "-c", fmt.Sprintf("%v %v %v %v", "/usr/bin/cp", "-r", sourceDir, targetDir)).Output(); err != nil {
fmt.Println(sourceDir, targetDir)
panic(err)
}
},
}