/
winexe.go
51 lines (41 loc) · 1.13 KB
/
winexe.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
package builtin
import (
"github.com/c4s4/neon/neon/build"
"github.com/c4s4/neon/neon/util"
"strings"
)
func init() {
build.AddBuiltin(build.BuiltinDesc{
Name: "winexe",
Func: winExe,
Help: `Add '.exe' or '.bat' extensions depending on platform:
- command will stay command on Unix and will become command.exe on Windows.
- script.sh will stay script.sh on Unix and will become script.bat on Windows.
It will also replace / with \ in the executable path.
Arguments:
- The command to process.
Returns:
- Command adapted to host system.
Examples:
# run command foo on unix and windows
run(winexe("bin/foo"))
# will run bin/foo on unix and bin\foo.exe on windows
# run script script.sh unix and windows
run(winexe("script.sh"))
# will run script.sh on unix and script.bat on windows`,
})
}
func winExe(command string) string {
if util.Windows() {
return toWindows(command)
}
return command
}
func toWindows(command string) string {
if strings.HasSuffix(command, ".sh") {
command = command[:len(command)-3] + ".bat"
} else {
command = command + ".exe"
}
return strings.Replace(command, "/", "\\", -1)
}