forked from deanishe/awgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
58 lines (41 loc) · 1.39 KB
/
util.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
// Copyright (c) 2018 Dean Jackson <[email protected]>
// MIT Licence - http://opensource.org/licenses/MIT
/*
Package util contains general helper functions for workflow (library) authors.
The functions can be divided into roughly three groups: paths, formatting
and scripting.
Paths
There are a couple of convenience path functions, MustExist and
ClearDirectory.
Formatting
PrettyPath for user-friendly paths, and the Pad* functions for padding
strings.
Scripting
QuoteAS quotes strings for insertion into AppleScript code and there
are several Run* functions for executing script code and files.
Run() // run a script file or executable & return output
RunAS() // run AppleScript code & return output
RunJS() // run JXA code & return output
RunCmd() // run *exec.Cmd & return output
Run takes the path to a script or executable. If file is executable,
it runs the file directly. If it's a script file, it tries to guess the
appropriate interpreter.
See Runner for more information.
*/
package util
import (
"log"
"time"
)
// Timed logs the duration since start & title. Use it with defer.
//
// func doSomething() {
// defer Timed(time.Now(), "long running task")
// // do thing here
// // and another thing
// }
// // Output: ... long running task
//
func Timed(start time.Time, title string) {
log.Printf("%s \U000029D7 %s", time.Since(start), title)
}