-
Notifications
You must be signed in to change notification settings - Fork 28
libubox: add convenience functions for moving the cursor #6
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
base: master
Are you sure you want to change the base?
Conversation
f10a21a to
104f923
Compare
|
@nbd168 Can I get a review please? I need some of these changes to help with a migration from ISC-DHCP to Kea. |
|
@jow- Can you please look this over? |
|
Most (all?) existing functions use reference style returns (caller passes a destination variable name, function populates it and uses it's numeric return value to signify success/error) while your new functions introduce echo style returns requiring calling code to use ugly subshell invocations. Personally I would also change the naming like that:
|
Thanks, making those changes now. By And Where do the functions
For instance, you could implement if |
104f923 to
02b2c90
Compare
|
Casting a wider net cc: @blogic |
|
Creating 2nd PR (#12) without the positioning getter/setting commit which seems to be stalled. |
@jow- I believe I've made these changes as requested. Can you please re-review? |
3ba2872 to
d1f6263
Compare
|
@jow- I believe I've addressed the comments you made. Can I get a merge please or a re-review? |
Still blocked on improvements to |
|
This migration is really important from ISC DHCP to Kea. |
|
I figure you have commit rights to fix this @pprindeville |
No, my rights are only for |
d1f6263 to
7ef9c6f
Compare
|
Get the test formalities fixed and then we can ping a maintainer. |
Do you know how to write test scripts? I've not dug into it. |
|
?
|
Is that a new requirement? |
7ef9c6f to
937a88e
Compare
bc91ae7 to
f97afd4
Compare
Sorry, misread. Thought you were suggesting we add test coverage as well. Which doesn’t seem like a bad idea. |
|
ping @robimarko for merge :) |
Nah - the commit subject requirement has been like that for a while. It makes the overview when all the commit subjects get collated for a release and for info on openwrt.org. |
|
I see that this makes JSON creation more powerful/flexible. A demonstration for this (how it could be used) would be nice. @pprindeville I tried to find the commit for that you need this new helper functions but I could not find it. I fear that this new functionality does not belong here and your dhcp server wrapper could be written differently. |
Have a look at https://github.com/openwrt/packages/pull/27439/files#diff-bb791b0d9dcf1149197b51b8d13ae098141248335e144d3dc9d9810758509ead in the file I've had to play games with Indeed, I've had to write it differently but any rewrite has highlighted deficiencies in the API. At a minimum The reason for this is as you add members inside an array, because names aren't required to be unique, you must reference them by their index... you can't use |
I only see Edit: and the whole (new) script is about converting configuration to JSON. That's what ucode is good at and shell scripts are not good at. So in the end you try to extend one tool for your use case while another one is actually made for it. It's not some old script that would be worth keeping for convenience. |
I have another version which uses
And I'm sure if I wait five minutes someone will tell me to write it in Lua. |
There are many possible paths. I still have the opinion that you are solving the wrong problem here by using a tool that is not made for that purpose and trying to "fix" this particular tool - shell scripts are not made for complex data transformations. |
|
I cannot unresolve the discussion about "eval export" in the added code and still consider it highly relevant and not resolved. |
I’m following the paradigms of the existing code. I’m trying to make a low-touch change. To scrub away all of the instances, I’d file a bug against that and hope that a maintainer takes it up. |
But shell libraries are for generating complex tree-structured data? That seems antithetical. A lot of effort goes into |
Write, as I explained previously I have two different versions of that script depending on whether I'm using
If shell scripts weren't good at it, we wouldn't even have |
I think it was the only option we had. It still works, but it's tricky to debug. |
No argument there. So that’s why I went with it two years ago. |
This line uses export without eval. Now we could look at the git blame about newer and older lines.
For simple cases (serial/linear writing), they are good enough. But as soon as you start reading them or write them non linear, it becomes bad.
https://github.com/openwrt/packages/pull/27439/commits is two years old? The world can change after proposing a change and it can happen that it is better to redo it due to that. If you are interested, I could try rewriting that PR. |
Then what's the point of
I started writing it two years ago, yeah. I finally pushed it as a draft to concretize the fact that there actually was tangible work that was blocking on the What's your point? That if this drags on any longer, then a third option might materialize and I'll be asked yet again to rewrite to the flavor-of-the-month? This is letting the perfect be the enemy of the good meanwhile people have no clean migration strategy away from and end-of-life product. |
Reading JSON?
No one asks to use the most recent option. But taking an old option that is so unsuitable that you want to modify it is an approach I do not support.
Use the "end of life product" (jshn.sh) as it is or use the new one. |
Then it wouldn't need setters or dump. |
Setters and dump for writing, |
|
|
The code search provides many examples for reading using this function. Writing can only be found in a procd helper script but this is for editing an existing JSON and not creating a brand new one. |
JSON might not be generated serial if it's synthesized from another source such as UCI with a different organizational structure. In that case, being able to randomly access arrays and objects in the synthetic JSON simplifies passes over the source material. Signed-off-by: Philip Prindeville <[email protected]>
f97afd4 to
9b3db60
Compare
|
Added test coverage. |
Two years on and I've made those changes... |
You might not always want to populate JSON serially, so a way to save/restore the cursor through a convenience function is handy.
Also, adding anonymous (unnamed) strings to an array isn't obvious, so added a convenience function for that.
Lastly, some minor cleanup to show what the parameters are to functions, etc.
Requires PR #16.