Sha256: b615a435988f7a0b514684ff8abefe50e801b4bde3c46e17d2cedbb03b898e42

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

module UltraCommandLine
  module Commands

    module Factory

      DEFAULT_BANNER = ''.freeze
      DEFAULT_COMMAND_TYPE = :bool

      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
        type = definition_hash.fetch(:type, DEFAULT_COMMAND_TYPE).to_sym
        create_command name, type, options_definition_hash, banner, manager
      end

      private

      def create_command(name, type, 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, type, banner, options: options
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ultra_command_line-0.4.16 lib/ultra_command_line/commands/factory.rb
ultra_command_line-0.4.15 lib/ultra_command_line/commands/factory.rb
ultra_command_line-0.4.14 lib/ultra_command_line/commands/factory.rb
ultra_command_line-0.4.13 lib/ultra_command_line/commands/factory.rb
ultra_command_line-0.4.12 lib/ultra_command_line/commands/factory.rb
ultra_command_line-0.4.10 lib/ultra_command_line/commands/factory.rb