lib/eco/cli/config/options_set.rb in eco-helpers-1.5.1 vs lib/eco/cli/config/options_set.rb in eco-helpers-1.5.2

- old
+ new

@@ -1,20 +1,36 @@ module Eco class CLI class Config class OptionsSet + include Eco::CLI::Config::Help attr_reader :core_config def initialize(core_config:) @core_config = core_config @options_set = {} + @description = {} end - def add(option) + # @return [String] summary of the options. + def help + ["The following are the available options:"].yield_self do |lines| + max_len = keys_max_len(@options_set.keys) + @options_set.keys.each do |key| + lines << help_line(key, @description[key], max_len) + end + lines + end.join("\n") + end + + # @param option [String] the command line option. + # @param desc [String] description of the option. + def add(option, desc = nil) raise "Missing block to define the options builder" unless block_given? callback = Proc.new [option].flatten.compact.each do |opt| @options_set[opt] = callback + @description[opt] = desc end self end def process(io:)