Sha256: c3f98c2eca53ae44657253fa4cedf22fb918a068a944768eb00f2c44ace11068

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

require 'paint'
require 'upoj-rb'

# Generator of GNU Screen configuration files.
module Scide

  # Current version.
  VERSION = File.open(File.join(File.dirname(__FILE__), '..', 'VERSION'), 'r').read

  # Exit status codes.
  #
  # ==== Codes
  # * <tt>unexpected</tt> - 1.
  # * <tt>invalid_argument</tt> - 2.
  # * <tt>not_initialized</tt> - 3.
  # * <tt>screen_not_found</tt> - 4.
  # * <tt>config_not_found</tt> - 10.
  # * <tt>config_not_readable</tt> - 11.
  # * <tt>malformed_config</tt> - 12.
  # * <tt>invalid_config</tt> - 13.
  # * <tt>unknown_project</tt> - 14.
  EXIT = {
    :unexpected => 1,
    :invalid_argument => 2,
    :not_initialized => 3,
    :screen_not_found => 4,
    :config_not_found => 10,
    :config_not_readable => 11,
    :malformed_config => 12,
    :invalid_config => 13,
    :unknown_project => 14
  }

  # Prints a message on <tt>stderr</tt> and exits.
  # If #condition is a key from #EXIT, the corresponding value
  # will be used as the exit code. Otherwise, scide exits with
  # status 1.
  def self.fail condition, msg
    if @@exit_on_fail
      puts
      warn Paint[msg, :yellow]
      puts
      EXIT.key?(condition) ? exit(EXIT[condition]) : exit(1)
    else
      raise Scide::Error.new condition, msg
    end
  end

  # By default, scide is meant to be used as a standalone script
  # and exits if an error occurs. If <tt>exit_on_fail</tt> is
  # false, a Scide::Error will be raised instead. Scide can then
  # be used by another script.
  def self.exit_on_fail= exit_on_fail
    @@exit_on_fail = exit_on_fail
  end

  # Scide error. Can be raised if #exit_on_fail is set to false.
  class Error < StandardError
    attr_reader :condition

    # Returns a new error.
    def initialize condition, msg
      super msg
      @condition = condition
    end
  end

  private

  @@exit_on_fail = true
end

# load scide components
%w( command config global opts overmind project screen window ).each{ |dep| require File.join(File.dirname(__FILE__), 'scide', dep) }

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scide-0.0.6 lib/scide.rb