jacobdeichert/mask

Forwarding arguments?

tonyb983 opened this issue · 1 comments

I'm not sure if this feature would be useful or necessary at all, and honestly this may just stem from my bash inexperience, but I'm having trouble forwarding (if this is the correct expression) arguments to a command that is run by mask.

For simplicity sake, say you are building a binary with cmake and attempting to run the output:

Binary usage is such:
$ ./HelloWorld -n <NAME> -l <LANG>

My mask script looks like this:

## standalone

> Builds and runs the standalone executable (cli) portion of the project

**OPTIONS**
* run
    * flags: -r --run
    * type: boolean
    * desc: Run the standalone executable after building

* args
    * flags: -a --args
    * type: string
    * desc: The args to pass to the executable when it is run (flag will be ignored if run is not also passed). If not provided the default will be '--help'.

```bash
INPUT_ARGS=${args:-"--help"}
cmake -S standalone -B build/standalone
cmake --build build/standalone

[[ "$run" == "true" ]] && ./build/standalone/HelloWorld $INPUT_ARGS
\```
(^ Ignore this backslash, it was the only way I could get this block to close)

But I'm getting errors from Mask regarding unexpected arguments (-n flag):

$ mask standalone -r -a "-n Tony"
error: Found argument '-n' which wasn't expected, or isn't valid in this context

USAGE:
    mask standalone --args <args> --run

For more information try --help

Please let me know if I'm doing something wrong or if this is indeed expected behavior, and whether there can be option to forward remaining args "inside" the mask command.

Edit: Sorry for the edit, I fat fingered control + enter to submit this too soon.
Edit2: I'm bad at formatting.

Hey @tonyb983, it appears you've found a bug with our argument parser!

I was testing this using the cmd block below to find out what was going on:

INPUT_ARGS=${args:-"--help"}
[[ "$run" == "true" ]] && echo "$INPUT_ARGS"

When running mask standalone -r --args "-" it succeeds and prints -.

However, when running mask standalone -r --args "-X" using any character where X is located, then I get the same error as you:

error: Found argument '-X' which wasn't expected, or isn't valid in this context

This is because our cli args parser (clap) seems to be confusing it for an argument even though it's wrapped in quotes.

I also tried adding a space after the quote and before the dash: mask standalone -r --args " -X". This actually works! You might be able to use this as a workaround in the meantime until we find a fix for this.

As for a real fix, we might be able to workaround that bug, but it's probably worth trying to update clap first and maybe taking a look at their documentation for an option we can use to allow/ignore dashed args it doesn't know about.