jawher/mow.cli

Question: Is it possible to signify nothing is parsed after argument?

gaffneyc opened this issue · 7 comments

I'm writing a command line utility that is designed to wrap the execution of other commands (it will have arguments of it's own). It will be common that a user would want to do something like this: mycmd their_command -c -F. I know this is currently possible using -- to say mycmd -- bash -c 'some code'.

The problem I expect to happen will be that if the user wraps a command without arguments it will work fine (e.g. mycmd echo foo) but the behavior would be different when using a command with a flag (e.g. mycmd bash -c 'echo foo').

Would it be possible to have an argument that nothing is parsed after this or to require "--" be used? I'm guessing I could precheck os.Args to ensure "--" exists before moving on to further parsing.

This is actually a bug: what you are describing should be possible to implement using this spec string:

app.Spec = "-c -- CMD [ARG...]"

i.e. by using the -- operator in the spec string to tell mow.cli that after the -c option, parse everything as an argument and ignore options.

I implemented the first half of this logic in the spec parser but I forgot to implement the second half.

So thanks for spotting it ! The fix is under way.

Huh interesting. To give a little bit more on what I'm doing I currently have: app.Spec = "-- CMD [ARG...]". myapp echo foo will do as you would expect but myapp bash -c 'echo foo' errors with Error: Illegal option -c.

Is it possible that it would know that -c is actually part of the bash call? I'm guessing not easily.

Yep, your spec string is absolutely correct, and the fact that you get the error you mention is a bug that I'm trying to fix as we're speaking.

Awesome (and thank you)! Wasn't sure if we were on the same page but seems we are.

The good news is that I located the origin of the bug and I have a rough idea on how to go about fixing it.

The bad news is that fixing it is going to require a fair chunk of work and rewriting parts of the parsing/normalization logic, so it might take a day or 2.

Thanks again for finding it and stay tuned.

Wonderful! Thanks for getting this fixed and keep up the good work.

Thanks !