-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.go
More file actions
66 lines (53 loc) · 1.24 KB
/
file.go
File metadata and controls
66 lines (53 loc) · 1.24 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
package main
import (
"bufio"
"fmt"
tColor "github.com/TwiN/go-color"
"html/template"
"log"
"os"
)
func htmlGenerator(cssify Cssify) {
prettyPrint("HTML Generated", true)
template, err := template.ParseFiles("./template/cssify.html")
if err != nil {
fmt.Println("Error: File could not be opened")
log.Fatal(err)
}
file := createFile()
writer := bufio.NewWriter(file)
if err := template.Execute(writer, cssify); err != nil {
fmt.Println("Error: Template could not be executed")
log.Fatal(err)
}
writer.Flush()
}
func createFile() *os.File {
prettyPrint("HTML File Created", true)
err := os.MkdirAll("./out/", 0700)
if err != nil {
fmt.Println("Error: Directory could not be created")
log.Fatal(err)
}
file, err := os.Create("./out/index.html")
if err != nil {
fmt.Println("Error: index.html could not be created")
log.Fatal(err)
}
return file
}
func fileOpen(path string) *os.File {
file, err := os.Open(path)
if err != nil {
fmt.Println("Error: File could not be opened")
log.Fatal(err)
}
return file
}
func printCommandHelp() {
fmt.Println(tColor.White + "CSSify is a tool to convert a image to HTML & CSS")
fmt.Print("\nUsage:\n\n")
fmt.Print("\tcssify <image path>\n\n")
fmt.Print("\n")
os.Exit(0)
}