I would like to construct a Cmd
with some optional parts, depending in the caller. I got this working by collecting strings and then interpolating a vector of them, and this actually works fine (with escaping, etc) but I am curious if there is some other way.
function make_cmd(file, options)
cmd_options = Any[]
options.debug ≠ nothing && push!(cmd_options, "--debug=$(options.debug)")
options.foo ≠ nothing && push!(cmd_options, "--foo=true")
options.somepath ≠ nothing && push!(cmd_options, "--somepath=$(options.somepath)")
`executable $(file) $(cmd_options)`
end
output:
julia> make_cmd("file.txt",
(debug = "/debug_output.log", foo = true,
somepath = "pathwith\"quote.txt"))
`executable file.txt --debug=/debug_output.log --foo=true '--somepath=pathwith"quote.txt'`