mask
mask copied to clipboard
Support infinite positional args
Maybe something like my cmd (files...).
Not sure what format to inject the environment variable string as though. Perhaps just comma separated? name1,name2,name3
## services start (services...)
~~~sh
echo "Starting all services: '$services'"
~~~
mask services start api proxy email
# Starting all services: 'api,proxy,email'
I'll take this one sometime this week.
I wonder if we can inject multiple environment variables in this case? Like
files_count=3files_1=apifiles_2=proxyfiles_3=emailfiles_all="api proxy email"
Particularly for bash some of the looping and comma-splitting is pretty annoying.
files_all="api proxy email"
I was thinking about space separation too since it works better for bash/shells. Though I'm not sure about setting the numbered variables on top of that (files_1 ... files_N).
Probably files="api proxy email" would be good enough 👍
While space separation works great for bash, I'm less sure about other runtimes. We could use spaces files="api proxy email" for all sh/fish/bash/zsh runtimes and perhaps use commas for all other runtimes files="api,proxy,email". Though the benefits of doing this are probably minimal and not worth it.
Sticking to spaces for all runtimes makes sense and keeps things consistent. I'll put some more thought into how this can go wrong...
One scenario i'm thinking of is this:
$ my_cmd file1 file2 file3 "file 4"
In bash, i'm pretty sure this would still be an array. But in a runtime like node, you can't just do process.env.files.split(' ') since that's not going to work in all scenarios.
While at it, I think a feature to limit the max number of args can be handy too. The syntax would be something like:
### watch build (files/2 option...)
```sh
watchexec "./script/build $files" --clear $option
```
inspired from Erlang/Elixir docs for function that take N args
Interesting idea!
I won't commit to that syntactical addition in this task, only because I feel like this could easily be done in the script's code if there absolutely needs to be a maximum for some reason. For example, a js script could easily do process.env.files.split(',').slice(0, MAX). I've just rarely found the need for a command to have a max amount of args specified.