Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support infinite positional args #4

Open
jacobdeichert opened this issue Jul 12, 2019 · 5 comments
Open

Support infinite positional args #4

jacobdeichert opened this issue Jul 12, 2019 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@jacobdeichert
Copy link
Owner

jacobdeichert commented Jul 12, 2019

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 jacobdeichert added the enhancement New feature or request label Jul 12, 2019
@jacobdeichert jacobdeichert self-assigned this Jul 22, 2019
@jacobdeichert
Copy link
Owner Author

I'll take this one sometime this week.

@felipesere
Copy link
Contributor

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.

@jacobdeichert
Copy link
Owner Author

jacobdeichert commented Jul 24, 2019

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.

@DrSensor
Copy link
Contributor

DrSensor commented Oct 3, 2019

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

@jacobdeichert
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants