-
Notifications
You must be signed in to change notification settings - Fork 0
/
neo.go
64 lines (53 loc) · 1.17 KB
/
neo.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
package main
import (
"encoding/json"
"io"
"log"
"os"
"os/exec"
"path"
"path/filepath"
)
var config = ".neo.json"
var mission = "default"
type Location struct {
Name string `json:"name"`
Dest string `json:"dest"`
Path string `json:"path"`
}
func Resolve(h, p, w string) error {
mission = h + "/" + p + "/" + w + "/s/" + mission
mCmd := exec.Command("/bin/bash", "-c", mission)
mCmd.Stdin = os.Stdin
mCmd.Stdout = os.Stdout
mCmd.Stderr = os.Stderr
mCmd.Start()
return mCmd.Wait()
}
// parse (JSON) config and if name matching this exectuable is found, dispatch to resolver
func Dispatch(d, e string) error {
var data []Location
config = d + "/" + config
jsonF, _ := os.Open(config)
defer jsonF.Close()
plan, _ := io.ReadAll(jsonF)
if json.Unmarshal(plan, &data) != nil {
log.Fatal("could not parse config")
}
for _, l := range data {
if e == l.Name {
return Resolve(d, l.Path, l.Dest)
}
}
log.Fatal("not ready yet.")
return nil
}
func main() {
log.Printf(string(os.Args[0]))
abs, err := filepath.EvalSymlinks(os.Args[0])
dir := path.Dir(abs)
exe := path.Base(abs)
log.Printf("Begin: %v", err)
err = Dispatch(dir, exe)
log.Printf("End : %v", err)
}