Sha256: e9f2ae25792e753e5c9d1d95a900ab73e4e7cb8718da6293073d845f88ea3de6

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

require 'climatic/config_layers/command_line_manager_binder'

module Climatic
  module ConfigLayers

    class CommandLineLayer < SuperStack::Layer

      include Climatic::ConfigLayers::CommandLineManagerBinder

      CONFIG_ROOT_DIR = %w(etc config).freeze
      DEFAULT_COMMAND_LINE_DEFINITION_FILE = 'command_line.yml'.freeze
      COMMAND_LINE_MANAGER_CLASS = UltraCommandLine::Manager::Base

      def initialize(command_line_manager = self.class.default_command_line_manager)
        # raise UltraCommandLine::Error, 'Invalid command line manager !' unless command_line_manager.is_a? MANAGER_CLASS
        @command_line_manager = command_line_manager
      end

      private

      def self.default_command_line_manager
        begin
          CONFIG_ROOT_DIR.each do |sub_dir|
            default_definition_file = File.join Climatic::ConfigLayers::ExecutableGemLayer.executable_gem_config_root, sub_dir, DEFAULT_COMMAND_LINE_DEFINITION_FILE
            if File.readable? default_definition_file
              return build_command_line_manager default_definition_file
            end
          end
        rescue => e
          Climatic.logger.debug "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
        end
        UltraCommandLine::Manager::Base.new
      end


      def self.build_command_line_manager(definition_file)
        mngr = COMMAND_LINE_MANAGER_CLASS.from_yaml_file definition_file
        mngr.definition_hash_to_commands
        mngr
      end


    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
climatic-0.2.40 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.39 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.38 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.37 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.36 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.35 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.34 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.32 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.31 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.30 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.29 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.28 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.27 lib/climatic/config_layers/command_line_layer.rb
climatic-0.2.26 lib/climatic/config_layers/command_line_layer.rb