Add bashio::var.json_array() function#194
Conversation
WalkthroughAdded a new public function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions. |
|
not stale |
|
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. Thank you for your contributions. |
|
not stale |
There was a problem hiding this comment.
Pull request overview
This PR extends the Bashio variable utilities by adding a helper to serialize Bash positional array values into a JSON array string, intended for embedding into bashio::var.json payloads.
Changes:
- Added
bashio::var.json_array()to convert positional arguments into a JSON array usingjq.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| local json_array | ||
|
|
||
| # https://stackoverflow.com/a/67489301/2755656 | ||
| if json_array=$(jq -cn '$ARGS.positional' --args -- "${array[@]}"); then |
There was a problem hiding this comment.
The jq invocation appears to place the --args option after the filter ('$ARGS.positional'). jq option parsing is not guaranteed to accept options after the filter (notably on stricter getopt implementations), which can lead to --args being treated as an input filename and the command failing. Reorder the command so --args is parsed as an option (and ensure -- is only used to terminate option parsing for the positional values).
| if json_array=$(jq -cn '$ARGS.positional' --args -- "${array[@]}"); then | |
| if json_array=$(jq -cn --args '$ARGS.positional' -- "${array[@]}"); then |
Proposed Changes
Can be used like:
Related Issues
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.