Sha256: ec972cc64f880d80a4edfba233a83a57b0728f76c319888286452af3716dfd83

Contents?: true

Size: 1.5 KB

Versions: 29

Compression:

Stored size: 1.5 KB

Contents

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

        # @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:)
          unless io && io.is_a?(Eco::API::UseCases::BaseIO)
            raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
          end

          @options_set.each do |arg, callback|
            callback.call(io.options, io.session) if SCR.get_arg(arg)
          end
          io.options
        end

      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
eco-helpers-2.0.16 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.15 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.14 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.13 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.12 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.11 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.10 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.9 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.8 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.7 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.6 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.5 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.4 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.3 lib/eco/cli/config/options_set.rb
eco-helpers-2.0.2 lib/eco/cli/config/options_set.rb
eco-helpers-1.5.15 lib/eco/cli/config/options_set.rb
eco-helpers-1.5.14 lib/eco/cli/config/options_set.rb
eco-helpers-1.5.13 lib/eco/cli/config/options_set.rb
eco-helpers-1.5.12 lib/eco/cli/config/options_set.rb
eco-helpers-1.5.11 lib/eco/cli/config/options_set.rb