Sha256: a08df8dd64a180c76f4dce0c4e1463d778d5bed2abc1ca61690d7541780b77dc

Contents?: true

Size: 950 Bytes

Versions: 2

Compression:

Stored size: 950 Bytes

Contents

module UltraCommandLine
  module Commands

    module Factory

      DEFAULT_BANNER = ''.freeze

      include UltraCommandLine::Utils::YamlFactory

      def from_hash(definition_hash, factory_options = {})
        name = factory_options.fetch :name, ''
        options_definition_hash = definition_hash.fetch(:options, {})
        manager = factory_options[:manager]
        banner = definition_hash.fetch :banner, DEFAULT_BANNER
        create_command name, options_definition_hash, banner, manager
      end

      private

      def create_command(name, options_definition_hash, banner, manager)
        options = options_definition_hash.map do |option_name, option_definition_hash|
          option_type = option_definition_hash[:type].to_sym
          UltraCommandLine::Commands::OptionDefinition.new option_name, option_type, option_definition_hash
        end
        new manager, name, banner, options: options
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ultra_command_line-0.4.8 lib/ultra_command_line/commands/factory.rb
ultra_command_line-0.4.7 lib/ultra_command_line/commands/factory.rb