lib/eco/cli/config.rb in eco-helpers-0.9.2 vs lib/eco/cli/config.rb in eco-helpers-0.9.3

- old
+ new

@@ -1,10 +1,72 @@ module Eco class CLI class Config + attr_reader :cli + def initialize(cli:) + @cli = cli + end + + def options + cli.options + end + + def args + cli.args + end + + def options_set + @opions_set ||= Eco::CLI::Config::OptionsSet.new(core_config: self) + @opions_set.tap do |opts_set| + yield(opts_set, options) if block_given? + end + end + + def input(default_option: nil) + @input ||= Eco::CLI::Config::Input.new(core_config: self, default_option: default_option) + if block_given? + @input.define(&Proc.new) + self + else + @input + end + end + + def people(io: nil) + if block_given? + @people_load = Proc.new + self + else + raise "There is no definition on how to load people" unless instance_variable_defined?(:@people_load) && @people_load + unless io && io.is_a?(Eco::API::UseCases::BaseIO) + raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}" + end + + io = io.new(type: :import) + @people_load.call(*io.params) + end + end + + def people_filters + @people_filters ||= Eco::CLI::Config::PeopleFilters.new(core_config: self) + @people_filters.tap do |filters| + yield(filters) if block_given? + end + end + + def usecases + @usecases ||= Eco::CLI::Config::UseCases.new(core_config: self) + @usecases.tap do |cases| + yield(cases) if block_given? + end + end + end end end -require_relative 'config/options' +require_relative 'config/options_set' +require_relative 'config/input' +require_relative 'config/people_filters' +require_relative 'config/use_cases'