File: applescript.go

package info (click to toggle)
golang-github-crc-org-crc 2.34.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,548 kB
  • sloc: sh: 398; makefile: 326; javascript: 40
file content (45 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download
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
//go:build !windows
// +build !windows

package applescript

import (
	"fmt"
	"path"
	"path/filepath"
	"runtime"
	"strings"

	"github.com/crc-org/crc/v2/test/extended/util"
)

func ExecuteApplescript(scriptFilename string, args ...string) error {
	command := strings.Join(append(
		append([]string{"osascript"}, scriptFilename),
		args...),
		" ")
	return util.ExecuteCommandSucceedsOrFails(command, "succeeds")
}

func ExecuteApplescriptReturnShouldMatch(expectedOutput string,
	scriptFilename string, args ...string) error {
	command := strings.Join(append(
		append([]string{"osascript"}, scriptFilename),
		args...),
		" ")
	err := util.ExecuteCommand(command)
	if err != nil {
		return err
	}
	return util.CommandReturnShouldMatch("stdout", expectedOutput)
}

func GetScriptsPath(scriptsRelativePath string) (string, error) {
	_, filename, _, ok := runtime.Caller(1)
	if ok {
		return string(path.Dir(filename) +
			string(filepath.Separator) +
			scriptsRelativePath), nil
	}
	return "", fmt.Errorf("error recovering required resources for applescript installer handler")
}