config :: IniConfig :: defaultinit
# Configuration class based on a INI file.
#
# ~~~
# class MyIniConfig
# super IniConfig
#
# var opt_my = new OptionString("My option", "--my")
#
# init do
# super
# tool_description = "Usage: MyExample [OPTION]... [ARGS]..."
# opts.add_option(opt_my)
# end
#
# fun my: String do return opt_my.value or else ini["my"] or else "Default"
# end
#
# var config = new MyIniConfig
# config.default_config_file = "my_config.ini"
# config.parse_options(args)
#
# if config.help then
# config.usage
# exit 0
# end
#
# assert config.my == "Default"
# ~~~
class IniConfig
super Config
# Config tree used to store config options
var ini: IniFile is noinit
# Path to app config file
var opt_config = new OptionString("Path to config file", "--config")
init do
super
opts.add_option(opt_config)
end
redef fun parse_options(args) do
super
ini = new IniFile.from_file(config_file)
end
# Default config file path
var default_config_file = "config.ini" is writable
# Return the config file path from options or the default
fun config_file: String do return opt_config.value or else default_config_file
end
lib/config/config.nit:270,1--322,3