It makes it very simple and intuitive to build command line apps.
It makes it very simple and intuitive to build command line apps.
For example for:
define_opt('server', 'daemon', type=bool, cmd_name='daemon', cmd_short_name='d')
Can I just write define_opt('daemon') ?
server - this is the section/module. I could grab this from the name of the current module, but that means you must use unique module names, and not change them. Otherwise, your config files would stop working.
daemon - required, obviously, since this is the name of the option.
type - I can't assume a type for you. By default it is a unicode instance, so you can omit this parameter if that's your use case.
cmd_name/cmd_short_name - I can try to assume that cmd_name is the same as the second positional argument, but once again, there could be a conflict. For example, if you want to have options.db.filename and options.log.filename, you can't use cmd_name = 'filename' for both. cmd_short_name is even worse, since here you may want a specific letter to be used (such as an upper case D instead of d). Note that these parameters are optional, since most of your values will likely go in the config file, not on the command line.
An alternative API might look like this:
define_opt_int('server', 'shutdown_timeout')
define_opt_bool('server', 'deameon')
define_opt_cmd_unicode('server', 'pid_file', cmd_name='pid', cmd_short_name='p')
With a fallback to: define_opt('log', 'level', type=lambda x: x if x in LOG_LEVELS else 'DEBUG', cmd_name='log-level', cmd_short_name='L')
Any feedback is greatly appreciated.Interesting module nonetheless!