Property definitions

popcorn $ AppConfig :: defaultinit
# Configuration file for Popcorn apps
#
# ~~~
# import popcorn
# import popcorn::pop_config
#
# # Build config from default values
# var config = new AppConfig
# config.parse_options(args)
#
# # Change config values
# config.ini["app.port"] = 3001.to_s
#
# # Use options
# var app = new App
# app.listen(config.app_host, config.app_port)
# ~~~
class AppConfig
	super IniConfig

	redef var default_config_file: String = "app.ini"

	# Host name to bind on (will overwrite the config one).
	var opt_host = new OptionString("Host to bind the server on", "--host")

	# Web app host name
	#
	# * key: `app.host`
	# * default: `localhost`
	fun app_host: String do return opt_host.value or else ini["app.host"] or else "localhost"

	# Port number to bind on (will overwrite the config one).
	var opt_port = new OptionInt("Port number to use", -1, "--port")

	# Web app port
	#
	# * key: `app.port`
	# * default: `3000`
	fun app_port: Int do
		var opt = opt_port.value
		if opt > -1 then return opt
		var val = ini["app.port"]
		if val != null then return val.to_i
		return 3000
	end

	# Displayed host name
	#
	# Specify this option if you need a qualified hostname to use within your handlers
	# and `app_host` requires something else like an IP to bind.
	# Really useful if the popcorn app runs behind a proxy.
	#
	# Default is `"{app_host}:{app_port}"`
	var opt_hostname = new OptionString("Displayed host name", "--hostname")

	# Displayed host name config
	#
	# * key: `app.hostname`
	# * default: `"{app_host}:{app_port}"`
	fun app_hostname: String do
		var opt = opt_hostname.value
		if opt != null then return opt
		var cfg = ini["app.hostname"]
		if cfg != null then return cfg
		var res = app_host
		if app_port != 80 then res = "{res}:{app_port}"
		return res
	end

	init do
		super
		add_option(opt_host, opt_port, opt_hostname)
	end
end
lib/popcorn/pop_config.nit:82,1--155,3