-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinj.go
53 lines (46 loc) · 1.21 KB
/
inj.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
package main
import (
"os"
"os/exec"
"path/filepath"
)
func main() {
// Get executable path
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath := filepath.Dir(ex)
// Get current working directory (where user runs the command)
userWorkDir, err := os.Getwd()
if err != nil {
panic(err)
}
// Prepare command
scriptPath := filepath.Join("dist", "inj.js")
// Convert relative paths in arguments to absolute paths
args := make([]string, len(os.Args[1:]))
for i, arg := range os.Args[1:] {
if filepath.IsAbs(arg) {
args[i] = arg
} else {
// Only convert if it looks like a file path
if _, err := os.Stat(filepath.Join(userWorkDir, arg)); err == nil {
args[i] = filepath.Join(userWorkDir, arg)
} else {
args[i] = arg
}
}
}
// Create command
cmd := exec.Command("node", scriptPath)
cmd.Args = append(cmd.Args, args...)
cmd.Dir = exPath
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
// Run
if err := cmd.Run(); err != nil {
os.Exit(1)
}
}