-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (39 loc) · 1.28 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
package main
import (
"flag"
"log"
"structure/utils"
)
func main() {
// Define the command-line flags
hereFlag := flag.Bool("here", false, "Create project structure in the current directory")
projectRootName := flag.String("project-root", "", "Name of the project root directory")
structFile := flag.String("structure", "structure.yaml", "YAML file containing the project structure")
flag.Parse()
// Parse the YAML structure
root, err := utils.ParseYAMLStructure(*structFile, *projectRootName)
if err != nil {
log.Fatalf("\033[1;33mError parsing structure: %v\033[0m", err)
}
var parentDir string
if *hereFlag {
// If --here is set, use the current directory
parentDir = "."
// Create children directly in the current directory
for _, child := range root.Children {
utils.MakeDirectoryAndFilesTree(child, parentDir)
}
} else {
// If --here is not set, require a project root name
if *projectRootName == "" {
log.Fatalf("\033[1;33mError: project root name is required when --here is not specified\033[0m")
}
err = utils.MakeDirectoryAndFilesTree(root, parentDir)
if err != nil {
log.Fatalf("\033[1;33mError creating directory and files: %v\033[0m", err)
}
}
if err != nil {
log.Fatalf("\033[1;33mError creating directory and files: %v\033[0m", err)
}
}