mask icon indicating copy to clipboard operation
mask copied to clipboard

Support infinite positional args

Open jacobdeichert opened this issue 6 years ago • 5 comments

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'

jacobdeichert avatar Jul 12 '19 03:07 jacobdeichert

I'll take this one sometime this week.

jacobdeichert avatar Jul 22 '19 04:07 jacobdeichert

I wonder if we can inject multiple environment variables in this case? Like

  • files_count=3
  • files_1=api
  • files_2=proxy
  • files_3=email
  • files_all="api proxy email"

Particularly for bash some of the looping and comma-splitting is pretty annoying.

felipesere avatar Jul 22 '19 21:07 felipesere

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.

jacobdeichert avatar Jul 24 '19 03:07 jacobdeichert

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

DrSensor avatar Oct 03 '19 00:10 DrSensor

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.

jacobdeichert avatar Oct 03 '19 03:10 jacobdeichert