SergioBenitez / Figment

A hierarchical configuration library so con-free, it's unreal.
Apache License 2.0
635 stars 38 forks source link

Allow Value::find to traverse arrays #92

Open thorio opened 9 months ago

thorio commented 9 months ago

Use Case

Given a configuration file like this:

providers:
  - plugin: calculator
    config:
      some_stuff: ""
  - plugin: websearch
    config:
      some_other_stuff: ""

I'd like to be able to focus on providers.1.config, merge/join other providers and then deserialize the contents into an arbitrary struct defined by the websearch plugin.

Petition

Currently, Value::find and, by proxy, Figment::focus work exclusively on dict keys, arrays are ignored. If we extend Value::find and Value::find_ref to attempt to index arrays, arrays can be traversed and the contained dicts found/focused on.

I managed to hack support into it on my fork and it works perfectly for my use case.

Is this feature wanted in this project? If so, I'd be happy to update find_ref, docs, tests and submit a PR.

luizfonseca commented 6 months ago

+1, This would be a nice addition (currently I can't "override" specific configs env-wise)