Refactor (macos).
This commit is contained in:
parent
08ed75b4c5
commit
a366be75f2
3 changed files with 9 additions and 5 deletions
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
package zenutil
|
package zenutil
|
||||||
|
|
||||||
import "encoding/json"
|
import (
|
||||||
import "text/template"
|
"encoding/json"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) {
|
var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) {
|
||||||
b, err := json.Marshal(v)
|
b, err := json.Marshal(v)
|
||||||
|
|
|
@ -100,8 +100,10 @@ var generator = template.Must(template.New("").Parse(`// Code generated by zenit
|
||||||
|
|
||||||
package zenutil
|
package zenutil
|
||||||
|
|
||||||
import "encoding/json"
|
import (
|
||||||
import "text/template"
|
"encoding/json"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) {
|
var scripts = template.Must(template.New("").Funcs(template.FuncMap{"json": func(v interface{}) (string, error) {
|
||||||
b, err := json.Marshal(v)
|
b, err := json.Marshal(v)
|
||||||
|
|
|
@ -23,9 +23,9 @@ func Run(ctx context.Context, script string, data interface{}) ([]byte, error) {
|
||||||
// Try to use syscall.Exec, fallback to exec.Command.
|
// Try to use syscall.Exec, fallback to exec.Command.
|
||||||
if path, err := exec.LookPath("osascript"); err != nil {
|
if path, err := exec.LookPath("osascript"); err != nil {
|
||||||
} else if t, err := ioutil.TempFile("", ""); err != nil {
|
} else if t, err := ioutil.TempFile("", ""); err != nil {
|
||||||
|
} else if err := os.Remove(t.Name()); err != nil {
|
||||||
} else if _, err := t.WriteString(script); err != nil {
|
} else if _, err := t.WriteString(script); err != nil {
|
||||||
} else if _, err := t.Seek(0, 0); err != nil {
|
} else if _, err := t.Seek(0, 0); err != nil {
|
||||||
} else if err := os.Remove(t.Name()); err != nil {
|
|
||||||
} else if err := syscall.Dup2(int(t.Fd()), syscall.Stdin); err != nil {
|
} else if err := syscall.Dup2(int(t.Fd()), syscall.Stdin); err != nil {
|
||||||
} else if err := os.Stderr.Close(); err != nil {
|
} else if err := os.Stderr.Close(); err != nil {
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue