Function expandExecArgs

Expand Exec arguments (usually returned by unquoteExec) replacing field codes with given values, making the array suitable for passing to spawnProcess. Deprecated field codes are ignored.

string[] expandExecArgs (
  scope const(string)[] unquotedArgs,
  scope const(string)[] urls = null,
  string iconName = null,
  string displayName = null,
  string fileName = null
) pure @trusted;

Note

Returned array may be empty and must be checked before passing to spawning the process.

Parameters

NameDescription
unquotedArgs Array of unescaped and unquoted arguments.
urls Array of urls or file names that inserted in the place of %f, %F, %u or %U field codes. For %f and %u only the first element of array is used. For %f and %F every url started with 'file://' will be replaced with normal path.
iconName Icon name used to substitute %i field code by --icon iconName.
displayName Name of application used that inserted in the place of %c field code.
fileName Name of desktop file that inserted in the place of %k field code.

Throws

DesktopExecException if command line contains unknown field code.

See Also

unquoteExec

Example

assert(expandExecArgs(
    ["program path", "%%f", "%%i", "%D", "--deprecated=%d", "%n", "%N", "%m", "%v", "--file=%f", "%i", "%F", "--myname=%c", "--mylocation=%k", "100%%"],
    ["one"],
    "folder", "program", "location"
) == ["program path", "%f", "%i", "--file=one", "--icon", "folder", "one", "--myname=program", "--mylocation=location", "100%"]);

assert(expandExecArgs(["program path", "many%%%%"]) == ["program path", "many%%"]);
assert(expandExecArgs(["program path", "%f"]) == ["program path"]);
assert(expandExecArgs(["program path", "%f%%%f"], ["file"]) == ["program path", "file%file"]);
assert(expandExecArgs(["program path", "%f"], ["file:///usr/share"]) == ["program path", "/usr/share"]);
assert(expandExecArgs(["program path", "%u"], ["file:///usr/share"]) == ["program path", "file:///usr/share"]);
assert(expandExecArgs(["program path"], ["one", "two"]) == ["program path"]);
assert(expandExecArgs(["program path", "%f"], ["one", "two"]) == ["program path", "one"]);
assert(expandExecArgs(["program path", "%F"], ["one", "two"]) == ["program path", "one", "two"]);
assert(expandExecArgs(["program path", "%F"], ["file://one", "file://two"]) == ["program path", "one", "two"]);
assert(expandExecArgs(["program path", "%U"], ["file://one", "file://two"]) == ["program path", "file://one", "file://two"]);

assert(expandExecArgs(["program path", "--location=%k", "--myname=%c"]) == ["program path", "--location=", "--myname="]);
assert(expandExecArgs(["program path", "%k", "%c"]) == ["program path", "", ""]);
assertThrown!DesktopExecException(expandExecArgs(["program name", "%y"]));
assertThrown!DesktopExecException(expandExecArgs(["program name", "--file=%x"]));
assertThrown!DesktopExecException(expandExecArgs(["program name", "--files=%F"]));