class Samovar::Options

def self.parse(*args, **options, &block)

def self.parse(*args, **options, &block)
	options = self.new(*args, **options)
	
	options.instance_eval(&block) if block_given?
	
	return options
end

def << option

def << option
	@ordered << option
	option.flags.each do |flag|
		@keyed[flag.prefix] = option
		
		flag.alternatives.each do |alternative|
			@keyed[alternative] = option
		end
	end
	
	if default = option.default
		@defaults[option.key] = option.default
	end
end

def initialize(title = "Options", key: :options)

def initialize(title = "Options", key: :options)
	@title = title
	@ordered = []
	
	# We use this flag to option cache to improve parsing performance:
	@keyed = {}
	
	@key = key
	
	@defaults = {}
end

def option(*args, **options, &block)

def option(*args, **options, &block)
	self << Option.new(*args, **options, &block)
end

def parse(input, default)

def parse(input, default)
	values = (default || @defaults).dup
	
	while option = @keyed[input.first]
		if result = option.parse(input)
			values[option.key] = result
		end
	end
	
	return values
end

def to_s

def to_s
	@ordered.collect(&:to_s).join(' ')
end

def usage(rows)

def usage(rows)
	@ordered.each do |option|
		rows << option
	end
end