Sha256: 5058f8c0ec01fec1def485af08bbefdd5b38d0898f6015956d87b713f02366f1

Contents?: true

Size: 1.64 KB

Versions: 14

Compression:

Stored size: 1.64 KB

Contents

module Climatic
  module Script

    module Base

      include Climatic::Utils::ScriptHelper

      module ClassMethods

        def start
          script = new
          script.run
        end

      end

      def run
        # logging startup configuration
        Climatic.config.command_line_layer.cmd_line_args = ARGV.dup
        Climatic.logger.debug "Config layers ->\n#{Climatic.config.detailed_layers_info}"
        Climatic.logger.debug "Merged config -> #{Climatic.config[].to_yaml}"
        # Displaying (and exiting) command line help
        display_help_and_exit if Climatic.config[:help]
        check_config
        Climatic.logger.info 'Application is starting...'
        do_process
        Climatic.logger.info 'Application ended normally...'
      rescue => e
        display_exit_error e
        exit_code = e.respond_to?(:exit_code) ? e.exit_code : 1
        exit exit_code
      ensure
        Climatic.logger.info 'Exiting...'
      end

      def self.included(base)
        base.extend ClassMethods
      end

      private

      def display_help_and_exit
        puts Climatic.config.command_line_help
        exit 0
      end

      def do_process
        cmd_line_mngr.processor.execute
      end

      def cmd_line_mngr
        Climatic.config.command_line_layer.command_line_manager
      end

      def check_config
        # Check options validity in terms of dependencies
        cmd_line_mngr.command.valid? raise_error: true
        # Delegates to the processor the functional checks of the config
        cmd_line_mngr.processor.check_params cmd_line_mngr.cmd_line_args_for_command(cmd_line_mngr.command)
      end

    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

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