Support optional arguments and sequences in cmd! #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows the
cmd!
macro to also splice in any sequence which implementsIntoIterator<Item: Into<OsString>>
. This requires a bit of extra syntax in thecmd!
macro since it would be possible for a type to implement bothInto<OsString>
andIntoIterator
. I ran into this pretty quickly once I started using this crate. It can be worked around by usingbefore_spawn
or directly using thecmd
function but it would be nice if it worked withcmd!
.So, in order to pass in a sequence to
cmd!
it needs to be prefixed with...
like this:I have chosen
...
here because...<expr>
is not a valid rust expression and so it shouldn't conflict with anything else. Unfortunately, it's not really possible to cleanly create a macro input which declaratively parses either...$arg
or$arg
so thecmd!
macro just takes a bunch of tokens and uses a second helper macro (cmd_expand_args!
) in order to parse that into something usable.Since
Option
also implementsIntoIterator
this can also be rather easily used for optional arguments as you can just do:I have tried to expand the docs with some examples to cover all of these use cases which should cover for the actual macro arguments shown in rustdoc being less readable now.
Fixes #88