-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfo.go
More file actions
135 lines (111 loc) · 4.02 KB
/
info.go
File metadata and controls
135 lines (111 loc) · 4.02 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"path"
"strconv"
"strings"
)
var listSpaces int = -3
func Info() {
if len(command.Args) < 1 {
command.LogError("No template name has been provided!")
}
template := command.CreateTemplateManager(command.Dirname()).GetTemplateInfo(strings.Join(command.Args, " "))
description := template.Description
preScripts := strings.Join(config.PreScripts, " && ")
ignore := strings.Join(config.Ignore, ", ")
if len(description) == 0 {
description = "No description."
}
if len(preScripts) == 0 {
preScripts = "No pre scripts."
}
if len(ignore) == 0 {
ignore = "No ignored files."
}
command.Println("Template information of [1m" + command.Args[0] + "[0m\n")
command.Println("[90m-[0m [1mName:[0m " + template.Name)
command.Println("[90m-[0m [1mDescription:[0m " + description)
command.Println("[90m-[0m [1mPre-Scripts:[0m " + preScripts)
command.Println("[90m-[0m [1mIgnored files:[0m " + ignore)
maxLength := 0
for name := range template.Scripts {
l := len(name)
if maxLength < l {
maxLength = l
}
}
if maxLength > 0 {
command.Println("[90m-[0m [1mScripts:[0m")
for name, script := range template.Scripts {
command.Println(" [90m-[0m [1m" + name + ":[0m" + strings.Repeat(" ", (maxLength-len(name))+3) + script)
}
}
}
func All() {
command.Print("[1mAll the templates saved.[0m\n\n")
templates := command.CreateTemplateManager(command.Dirname()).GetAllTemplates()
if len(templates) == 0 {
command.Println("No templates have been saved.")
} else {
for i, template := range templates {
command.Println("[1m" + strconv.Itoa(i+1) + ".[0m " + template[1:])
}
}
command.Println("\nYou can use [90mtemplatify info <template-name>[0m to show the information!")
}
func List() {
if len(command.Args) < 1 {
command.LogError("No template name has been provided!")
}
dirData := ReadDir(path.Join(command.Dirname(), "templates", command.Args[0]))
lockExists := false
for _, file := range dirData {
if file.Name == "templatify.lock.json" {
lockExists = true
}
}
if !lockExists {
command.LogError("Unknown template \"" + command.Args[0] + "\".")
}
command.Print("Template structure for [1m" + command.Args[0] + "[0m\n\n")
pushList(dirData)
}
func pushList(assets []FolderAsset) {
listSpaces += 3
for _, asset := range assets {
if asset.IsDir {
command.Println(strings.Repeat(" ", listSpaces) + "[90m-[0m " + asset.Name + "/")
pushList(asset.Assets)
} else {
command.Println(strings.Repeat(" ", listSpaces) + "[90m-[0m " + asset.Name)
}
}
}
func Help() {
help := []string{
"[1mTemplatify Commands[0m",
"[90m[arg] means optional argument and <arg> means required argument.[0m\n",
"help To show this help page",
"all Shows all the templates saved",
"removeall Removes all the templates",
"init Creates a default templatify.config.json",
"pre-scripts Runs the pre scripts saved in the lock",
"save [90m[name][0m Save the current working directory as a template!",
" [90m--clean[0m Total rewrite over the old template else will just merge",
"use [90m<name>[0m Use a template",
" [90m--custom-path=<path>[0m Set a custom path to use the template else will use the path as current working directory",
" [90m--no-git[0m Will not clone .git folder",
" [90m--remove-lock[0m Will remove templatify's lock file",
" [90m--disable-pre-scripts[0m Will not run pre scripts",
"get [90m<repo>[0m Download a repo as a template",
"info [90m<name>[0m Shows info of a template",
"list [90m<name>[0m Returns the folder map of the template",
"remove [90m<name>[0m Delete a template",
"exec [90m<name>[0m Execute a script by its name",
"test Executes the test script if it exists",
"\nYou can read the guide in github [94;4mhttps://github.com/scientific-guy/templatify[0m.",
}
for _, str := range help {
command.Println(str)
}
}