staffanm / layeredconfig

Manages configuration coming from config files, environment variables, command line arguments, code defaults or other sources
BSD 3-Clause "New" or "Revised" License
18 stars 8 forks source link

Commandline Source Hierarchical Param Always Converted to Array #9

Closed numbnut closed 8 years ago

numbnut commented 8 years ago

Hi, I'm facing an issue using the Commandline source. If I define a hierarchical command line param like --db_host=myhost.org it is always parsed as an array. I think this is a bug.

Example:

file config_cmd_bug.py

from layeredconfig import LayeredConfig, Commandline

config = LayeredConfig(Commandline())

print("{}".format(config))

invocation

python config_cmd_bug.py --dbhost=string --db_host=array_of_strings

results in

'db': {'host': ['array_of_strings']}, 'dbhost': 'string'}

Thanks for the nice lib!

staffanm commented 8 years ago

Thanks for the report! Yes, this does indeed look like a bug, and I've been able to reproduce it with a unit test, so I hope to have it fixed soon.

staffanm commented 8 years ago

Quick update: The last argument in your sample invocation (--db_host=array_of_strings) uses a non-default separator between the section (db) and the parameter (host). The separator is normally -, so if using --db-host=array_of_string it works as expected.

However, the separator should be configurable, and when setting it to _ (using the sectionsep parameter to Commandline) the problem still persists. It's also probably a bug that a character not defined as a section separator sort of acts like it. But using eg --db-host=... might be a workaround for now.

numbnut commented 8 years ago

Thanks for the fast response! Next time I will try to submit a test case.

numbnut commented 8 years ago

By the way I totally agree with you.

staffanm commented 8 years ago

Fixed in the above commit. I'll try to push a 0.3.2 release to pypi this week. Again, thanks for the bug report!

numbnut commented 8 years ago

Very nice! Thank you so much!

staffanm commented 8 years ago

Version 0.3.2 with this fix applied is now up on pypi.

numbnut commented 8 years ago

Nice! Thank you!