-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (42 loc) · 971 Bytes
/
main.go
File metadata and controls
49 lines (42 loc) · 971 Bytes
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
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
)
func main() {
var projectPath string
if len(os.Args) > 1 {
projectPath = os.Args[1]
} else {
var err error
projectPath, err = os.Getwd()
if err != nil {
fmt.Println("Error getting current directory:", err)
return
}
}
err := validatePath(projectPath)
if err != nil {
fmt.Println("Invalid path:", err)
return
}
tree, err := generateTree(projectPath, "")
if err != nil {
fmt.Println("Error generating tree structure:", err)
return
}
readmePath := filepath.Join(projectPath, "README.md")
file, err := os.OpenFile(readmePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
fmt.Println("Error opening/creating README.md:", err)
return
}
defer file.Close()
writer := bufio.NewWriter(file)
writer.WriteString("\n\n### Tree structure of the project:\n\n")
writer.WriteString(tree)
writer.Flush()
fmt.Println("Tree structure created successfully!")
}