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

List of key-value pairs (option to not split paths by dot) #214

Closed
EbonJaeger opened this issue Aug 6, 2021 · 5 comments
Closed

List of key-value pairs (option to not split paths by dot) #214

EbonJaeger opened this issue Aug 6, 2021 · 5 comments
Milestone

Comments

@EbonJaeger
Copy link

Perhaps more of just a question than an issue, but in a config I would like to have a list of key-value pairs, for example:

homes:
  limit-permissions:
    - example.node: 10
    - example.node.other: 20

I tried using a MapProperty, but that doesn't seem to do what I want; it expects {ebonhomes.limits.example2=20, ebonhomes.limits.example=10}.

I could just do a list of Strings and split on :, but that's ugly, and I'd really not have to do that.

Is there something here that I missed that'll do what I want?

@ljacqu
Copy link
Member

ljacqu commented Aug 30, 2021

Sorry for only answering now—feel free to ping me if I don't get back to issues after 7 days because when that happens, 95% of the time it's because I somehow didn't see it :(

I see what you're trying to do and it would work for strings with no dots in them. Dots are an alternative way to delimit paths, so the following two YAML excerpts are loaded the same way in ConfigMe's eyes:

homes.limits.test: 5
homes:
  limits:
    test: 5

Probably for your use case it would be enough to have a configurable way to turn this off?

Edit: Just need to make sure that turning it off won't conflict with how property paths are defined in ConfigMe in Java (e.g. newProperty("homes.limits.test", "default")) but as far as I can tell they don't conflict and I also don't think it's an issue semantically to tell those two usages apart. Just means that at a later time if you want to manipulate a file with concrete property paths it won't be possible since dots are picked up as path limits

@EbonJaeger
Copy link
Author

Crap, I forgot that dots are special in YAML. It's been a while... I usually work with TOML these days lol

Actually, specifying permission nodes like

homes:
  limits:
    blah: 10

should probably work... No reason they have to be a single string. I guess the question then becomes "how to I access them?"

I guess it would just be a list, right? Or would it be a map... Or I'm way off.

@ljacqu
Copy link
Member

ljacqu commented Sep 3, 2021

As far as I understand, dots don‘t mean anything special in YAML and the example in your initial post is perfectly valid and not equal to the nested equivalent.
ConfigMe converts dots to nested paths because Bukkit did the same, and to be honest I‘m not sure there‘s a better reason other than that. 😄
It‘s a bit hard to handle your permission nodes as nested paths because they can‘t really be represented as a bean, meaning you‘d have to probably read the data from the file reader itself… It‘s a pain and I think it would be fine to offer an option in ConfigMe to not split dots. If you can wait for it one week, maybe two, I would solve it like this :)

@EbonJaeger
Copy link
Author

Ahh, okay. Yeah, there's no rush. Thanks for the help!

@ljacqu ljacqu added this to the 1.3.0 Release milestone Sep 12, 2021
ljacqu added a commit that referenced this issue Sep 12, 2021
- Add option to preserve dots in paths for Map properties
- Open point: writing to resource still splits paths
ljacqu added a commit that referenced this issue Sep 13, 2021
- Make YamlFileResource aware on writing that keys from a map might not have to be split by '.'
- Change PropertyPathTraverser to take in a list of path elements instead of blindly splitting a single String
@ljacqu
Copy link
Member

ljacqu commented Sep 29, 2021

This is fixed minus some last testing. I haven't forgotten about this but the laptop I used to release from crashed so I have to set everything back up and it hasn't been motivating me. It's still on my radar though!

ljacqu added a commit that referenced this issue Oct 17, 2021
@ljacqu ljacqu changed the title List of key-value pairs List of key-value pairs (option to not split paths by dot) Oct 17, 2021
@ljacqu ljacqu closed this as completed Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants