Sha256: 1d845df3c0e9734bce6a51c22af336fe1671a4a291e839fe3bdbd949540bd015

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Chronicle
  module ETL
    module CLI
      # Base class for CLI commands
      class CLIBase < ::Thor
        no_commands do
          # Shorthand for cli_exit(status: :failure)
          def cli_fail(message: nil, exception: nil)
            if exception && Chronicle::ETL::Logger.log_level > Chronicle::ETL::Logger::DEBUG
              message += "\nRe-run the command with --verbose to see details."
            end

            cli_exit(status: :failure, message: message, exception: exception)
          end

          # Exit from CLI
          #
          # @params status Can be eitiher :success or :failure
          # @params message to print
          # @params exception stacktrace if log_level is set to debug
          def cli_exit(status: :success, message: nil, exception: nil)
            exit_code = status == :success ? 0 : 1
            log_level = status == :success ? :info : :fatal

            message = message.red if status != :success

            Chronicle::ETL::Logger.debug(exception.full_message) if exception
            Chronicle::ETL::Logger.send(log_level, message) if message
            exit(exit_code)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chronicle-etl-0.6.1 lib/chronicle/etl/cli/cli_base.rb
chronicle-etl-0.5.5 lib/chronicle/etl/cli/cli_base.rb
chronicle-etl-0.5.4 lib/chronicle/etl/cli/cli_base.rb