Skip to content

feat: custom separators for variadic flags #76

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

Merged
merged 2 commits into from
Apr 23, 2025
Merged

Conversation

molisani
Copy link
Member

@molisani molisani commented Apr 1, 2025

Resolves #74

Describe your changes
Allow variadic option for flags to be a string. If set, Stricli will use that string as a separator and call .split(separator) on every raw input (before it is parsed/validated).

For example, variadic: "," will split the raw input --flag 1,2,3 into ["1", "2", "3"] which will each be parsed separately (assuming this is a parsed number flag). This can still be combined with multiple instances of the same flag, so --flag 1,2 --flag 3 will be ["1", "2", "3"] as well.

Testing performed
Added several new test cases to achieve complete coverage.

Additional context
I've also added some additional validation to the flag specification, as the separator cannot be the empty string and should not include any whitespace.

Note: I don't know what would be the best way to indicate this behavior in the help text. I experimented with --flag <placeholder><separator><placeholder> but that got too verbose too fast.

@molisani molisani added the enhancement ✨ New feature or request label Apr 1, 2025
@molisani molisani self-assigned this Apr 1, 2025
@molisani molisani requested a review from a team as a code owner April 1, 2025 18:33
@molisani molisani force-pushed the fix/variadic-separator branch from eba8305 to c9c193b Compare April 1, 2025 18:33
@github-actions github-actions bot added core ⚙ Relates to the @stricli/core package documentation 📝 Improvements or additions to documentation labels Apr 1, 2025
mkubilayk
mkubilayk previously approved these changes Apr 11, 2025
@mkubilayk
Copy link
Collaborator

Note: I don't know what would be the best way to indicate this behavior in the help text. I experimented with --flag <placeholder><separator><placeholder> but that got too verbose too fast.

We could use the right aligned [...] section to mention the separator in the help text.

  -m [--mode]...           Brief                            [separator = ,]

@molisani
Copy link
Member Author

Note: I don't know what would be the best way to indicate this behavior in the help text. I experimented with --flag <placeholder><separator><placeholder> but that got too verbose too fast.

We could use the right aligned [...] section to mention the separator in the help text.

  -m [--mode]...           Brief                            [separator = ,]

That works very nicely as variadic flags can't have default values, so they won't have to stack.

@molisani molisani force-pushed the fix/variadic-separator branch from 9e9afdb to af362ec Compare April 15, 2025 16:49
@molisani molisani requested a review from mkubilayk April 23, 2025 14:47
@molisani molisani merged commit 68ff1d8 into main Apr 23, 2025
3 checks passed
@molisani molisani deleted the fix/variadic-separator branch April 23, 2025 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core ⚙ Relates to the @stricli/core package documentation 📝 Improvements or additions to documentation enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Would be great if variadic didn't require repeating the flag over and over
2 participants