class ToArgs a where
toArgs : a -> Array String
instance ToArgs String where
toArgs a = [a]
instance ToArgs a => ToArgs (Array a) where
toArgs = flatMap toArgs
[x] Desugar interpolation inside commands into calls to toArgs
\a -> `echo $a`
elaborates to
\a -> cmd (["echo"] ++ toArgs a)
[x] Document ToArgs in reference
Notes
The use of flatMap means that nested arrays are flattened when used as command arguments. I'm okay with this, because I'm not sure there are any other useful ways to interpret nested arrays of command line arguments.
Depends on #134.
Command literals should support interpolation for strings and arrays.
Examples
1.
is equivalent to
When interpolating an array, each item of the array is an argument to the command.
2.
is equivalent to
When an array item contains spaces, that item is still treated as a single argument rather than multiple arguments.
3.
When an expression is interpolated into a quoted argument, that expression is treated as a string.
4.
When an expression is interpolated and unquoted, that expression is treated as an argument list.
Implementation
[x] https://github.com/LightAndLight/ipso/issues/142
[x] Implement
ToArgs
class[x] Desugar interpolation inside commands into calls to
toArgs
elaborates to
[x] Document
ToArgs
in referenceNotes
flatMap
means that nested arrays are flattened when used as command arguments. I'm okay with this, because I'm not sure there are any other useful ways to interpret nested arrays of command line arguments.