-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagham_script.jl
More file actions
66 lines (61 loc) · 2.04 KB
/
diagham_script.jl
File metadata and controls
66 lines (61 loc) · 2.04 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
56
57
58
59
60
61
62
63
64
65
66
"""
diagham_command(execute; kwargs...)
Construct a command string for running a DiagHam executable with specified kwargs as CLI flags.
"""
function diagham_command(execute::AbstractString; kwargs...)
return diagham_command([execute]; kwargs...)
end
function diagham_command(
execute::AbstractVector{<:AbstractString};
diagham_path::AbstractString = get_diagham_path(),
kwargs...
)
warn_about_diagham_path()
ex_file = first(execute)
execute[1] = joinpath(diagham_path, ex_file)
execute = prod(execute)
## Now, we add kwargs to the command:
for (k, v) in kwargs
execute *= diagham_kwarg(k, v)
end
return execute
end
function diagham_kwarg(key, value)
key = replace("$key", "_" => "-")
key_print = length(key) == 1 ? " -$(key)" : " --$(key)"
if value isa Bool
if value
return key_print
end
else
return "$(key_print) $(value)"
end
return ""
end
"""
execute_diagham_script(execute; kwargs...)
Run a DiagHam executable. Kwargs are converted to CLI flags (`_` → `-`).
Single-char keys use `-k`, multi-char use `--key`. Boolean `true` adds flag, `false` omits.
The kwargs of `Cmd()` and `run()` are supported.
"""
function execute_diagham_script(execute::AbstractString; kwargs...)
return execute_diagham_script([execute]; kwargs...)
end
function execute_diagham_script(
execute::AbstractVector{<:AbstractString};
diagham_path::AbstractString = get_diagham_path(),
ignorestatus::Bool = false,
detach::Bool = false,
windows_verbatim::Bool = false,
windows_hide::Bool = false,
env = nothing,
dir = "",
wait::Bool = true,
cleanup::Bool = false,
kwargs...
)
execute = diagham_command(execute; diagham_path, kwargs...)
execute = Cmd(split(execute, " "))
cmd = Cmd(execute; ignorestatus = ignorestatus, detach = detach, windows_verbatim = windows_verbatim, windows_hide = windows_hide, env = env, dir = dir)
return run(cmd; wait = wait)
end