forked from ljanyst/ghostscad
/
stub_generator.go
64 lines (53 loc) · 1.24 KB
/
stub_generator.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
// Copyright 2022 Lukasz Janyst <lukasz@jany.st>
// Licensed under the MIT license, see the LICENSE file for details.
package main
import (
"flag"
"fmt"
"os"
"os/exec"
)
var stub = `
package main
import (
// "github.com/0daryo/ghostscad/lib/shapes"
"github.com/0daryo/ghostscad/sys"
// . "github.com/go-gl/mathgl/mgl64"
. "github.com/0daryo/ghostscad/primitive"
)
func main() {
sys.Initialize()
sys.SetFn(120)
sys.RenderOne(NewSphere(10))
}
`
func main() {
fileName := flag.String("file-name", "main.go", "name of the output file to put the code in")
flag.Parse()
file, err := os.OpenFile(*fileName, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
fmt.Printf("[!] Error while opening file: %s", err)
os.Exit(1)
}
n, err := file.WriteString(stub)
if n != len(stub) {
file.Close()
fmt.Printf("[!] Managed to writy %d chars out of %d", n, len(stub))
os.Exit(1)
}
if err != nil {
file.Close()
fmt.Printf("[!] Error while writing: %s", err)
os.Exit(1)
}
file.Sync()
file.Close()
cmd := exec.Command("go", "fmt", *fileName)
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
fmt.Printf("[!] Error while formatting: %s", err)
os.Exit(1)
}
}