-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
55 lines (51 loc) · 1.78 KB
/
init.lua
File metadata and controls
55 lines (51 loc) · 1.78 KB
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
local obj = {}
obj.__index = obj
-- Metadata
obj.name = "TaskHelper"
obj.version = "0.0.1"
obj.author = "Jacob Williams <jacobaw@gmail.com>"
obj.license = "MIT - https://opensource.org/licenses/MIT"
obj.homepage = "https://github.com/brokensandals/motley-hammerspoons"
--- TaskHelper.logger
--- Variable
--- An instance of hs.logger
obj.logger = hs.logger.new('TaskHelper', 'info')
--- TaskHelper.run(title, path[, arguments[, options]])
--- Function
--- Runs the executable at the given path, with the given table of arguments.
--- If the exit code is nonzero, a failure notification will be shown.
--- Stdout and stderr are output with TaskHelper.logger at info and warning level respectively
--- Options:
--- notifyOnSuccess: if true, show a temporary success notification when the command completes successfully
function obj.run(title, path, arguments, options)
options = options or {}
function taskCallback(exitCode, stdOut, stdErr)
logTitle = title .. " " .. path .. " " .. hs.inspect.inspect(arguments)
exitMsg = "returned " .. exitCode
logExitMsg = logTitle .. " " .. exitMsg
notifMsg = path .. " " .. exitMsg
if exitCode == 0 then
obj.logger.i(logExitMsg)
if options.notifyOnSuccess then
hs.notify.show(title, 'Succeeded', notifMsg)
end
else
obj.logger.w(logExitMsg)
hs.notify.new({
title = title,
subTitle = "Failed",
informativeText = notifMsg,
autoWithdraw = false,
withdrawAfter = 0
}):send()
end
if stdOut and stdOut ~= '' then
obj.logger.i('stdout for ' .. logTitle .. ':\n' .. stdOut)
end
if stdErr and stdErr ~= '' then
obj.logger.w('stderr for ' .. logTitle .. ':\n' .. stdErr)
end
end
hs.task.new(path, taskCallback, arguments):start()
end
return obj