This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rust.go
74 lines (59 loc) · 1.89 KB
/
rust.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
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
package templates
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/abdfnx/botway/constants"
"github.com/abdfnx/looker"
)
func MainRsContent(platform string) string {
return Content("src/main.rs", platform+"-rust", "", "")
}
func CargoFileContent(botName, platform string) string {
return Content("Cargo.toml", platform+"-rust", botName, "")
}
func RustTemplate(botName, platform, pm string) {
_, err := looker.LookPath("cargo")
pmPath, perr := looker.LookPath(pm)
if err != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" cargo is not installed"))
} else if perr != nil {
fmt.Print(constants.FAIL_BACKGROUND.Render("ERROR"))
fmt.Println(constants.FAIL_FOREGROUND.Render(" " + pm + " is not installed"))
} else {
mainFile := os.WriteFile(filepath.Join(botName, "src", "main.rs"), []byte(MainRsContent(platform)), 0644)
cargoFile := os.WriteFile(filepath.Join(botName, "Cargo.toml"), []byte(CargoFileContent(botName, platform)), 0644)
dockerFile := os.WriteFile(filepath.Join(botName, "Dockerfile"), []byte(DockerfileContent(botName, pm+".dockerfile", platform)), 0644)
resourcesFile := os.WriteFile(filepath.Join(botName, "resources.md"), []byte(Resources(platform, "rust.md")), 0644)
if resourcesFile != nil {
log.Fatal(resourcesFile)
}
if mainFile != nil {
log.Fatal(mainFile)
}
if cargoFile != nil {
log.Fatal(cargoFile)
}
if dockerFile != nil {
log.Fatal(dockerFile)
}
pmBuild := pmPath + " build"
buildCmd := exec.Command("bash", "-c", pmBuild)
if runtime.GOOS == "windows" {
buildCmd = exec.Command("powershell.exe", pmBuild)
}
buildCmd.Dir = botName
buildCmd.Stdin = os.Stdin
buildCmd.Stdout = os.Stdout
buildCmd.Stderr = os.Stderr
err = buildCmd.Run()
if err != nil {
log.Printf("error: %v\n", err)
}
CheckProject(botName, platform)
}
}