expandExecArgs

Expand Exec arguments (usually returned by unquoteExec) replacing field codes with given values, making the array suitable for passing to spawnProcess or spawnProcessDetached. Deprecated field codes are ignored. Note: Returned array may be empty and must be checked before passing to spawning the process.

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

Parameters

unquotedArgs
Type: string[]

Array of unescaped and unquoted arguments.

urls
Type: string[]

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
Type: string

Icon name used to substitute %i field code by --icon iconName.

displayName
Type: string

Name of application used that inserted in the place of %c field code.

fileName
Type: string

Name of desktop file that inserted in the place of %k field code.

Throws

DesktopExecException if command line contains unknown field code.

Examples

1 assert(expandExecArgs(
2     ["program path", "%%f", "%%i", "%D", "--deprecated=%d", "%n", "%N", "%m", "%v", "--file=%f", "%i", "%F", "--myname=%c", "--mylocation=%k", "100%%"],
3     ["one"],
4     "folder", "program", "location"
5 ) == ["program path", "%f", "%i", "--file=one", "--icon", "folder", "one", "--myname=program", "--mylocation=location", "100%"]);
6 
7 assert(expandExecArgs(["program path", "many%%%%"]) == ["program path", "many%%"]);
8 assert(expandExecArgs(["program path", "%f"]) == ["program path"]);
9 assert(expandExecArgs(["program path", "%f%%%f"], ["file"]) == ["program path", "file%file"]);
10 assert(expandExecArgs(["program path", "%f"], ["file:///usr/share"]) == ["program path", "/usr/share"]);
11 assert(expandExecArgs(["program path", "%u"], ["file:///usr/share"]) == ["program path", "file:///usr/share"]);
12 assert(expandExecArgs(["program path"], ["one", "two"]) == ["program path"]);
13 assert(expandExecArgs(["program path", "%f"], ["one", "two"]) == ["program path", "one"]);
14 assert(expandExecArgs(["program path", "%F"], ["one", "two"]) == ["program path", "one", "two"]);
15 assert(expandExecArgs(["program path", "%F"], ["file://one", "file://two"]) == ["program path", "one", "two"]);
16 assert(expandExecArgs(["program path", "%U"], ["file://one", "file://two"]) == ["program path", "file://one", "file://two"]);
17 
18 assert(expandExecArgs(["program path", "--location=%k", "--myname=%c"]) == ["program path", "--location=", "--myname="]);
19 assert(expandExecArgs(["program path", "%k", "%c"]) == ["program path", "", ""]);
20 assertThrown!DesktopExecException(expandExecArgs(["program name", "%y"]));
21 assertThrown!DesktopExecException(expandExecArgs(["program name", "--file=%x"]));
22 assertThrown!DesktopExecException(expandExecArgs(["program name", "--files=%F"]));

See Also

Meta