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"
config :: IniConfig :: config_file
Return the config file path from options or the defaultconfig :: IniConfig :: default_config_file=
Default config file pathconfig :: IniConfig :: defaultinit
config :: IniConfig :: opt_config=
Path to app config fileconfig $ IniConfig :: parse_options
Initializeself
options from args
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
config :: IniConfig :: config_file
Return the config file path from options or the defaultconfig :: IniConfig :: default_config_file=
Default config file pathcore :: Object :: defaultinit
config :: Config :: defaultinit
config :: IniConfig :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
config :: Config :: opt_black_exts=
--blacklist-extsconfig :: Config :: opt_black_exts=
--blacklist-extsconfig :: IniConfig :: opt_config=
Path to app config fileconfig :: Config :: opt_java_cp
config :: Config :: opt_java_cp=
config :: Config :: opt_stub_man=
Option --stub-manconfig :: Config :: opt_white_exts=
--whitelist-extsconfig :: Config :: opt_white_exts=
--whitelist-extscore :: Object :: output_class_name
Display class name on stdout (debug only).config :: Config :: parse_options
Initializeself
options from args
config :: Config :: tool_description
Name, usage and synopsis of the tool.config :: Config :: tool_description=
Name, usage and synopsis of the tool.
# 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