Sha256: a79ecbc5843a8226da3e98ea1b8e18207be4bd5d6087b5979b3d654d91becbca

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'yaml'
require 'cabal'
require 'cabal/cli/ssh'
require 'cabal/cli/key'
require 'cabal/cli/list'
require 'cabal/cli/main'

module Cabal
  # Bootstrap and configure the CLI application
  module CLI
    # The expected config file does not exist
    NoConfig = Class.new(StandardError)

    # The config file does not contain a :url
    NoURLDefinition = Class.new(StandardError)

    # The config file does not contain :access_key and :secret_key
    NoPrivateConfig = Class.new(StandardError)

    # Calculates the expected path of the Cabal config file
    # @return [String] the config file path
    def self.cabal_yml
      File.expand_path(File.join(ENV['HOME'], '.cabal.yml'))
    end

    # Parses the config file and sets up the global configuration
    # @return [nil]
    def self.setup
      if File.exist?(cabal_yml)
        @config = YAML.load(File.read(cabal_yml))

        raise NoURLDefinition.new("#{cabal_yml} must contain a :url: definition") unless config[:url]
      else
        raise NoConfig.new("Please create #{cabal_yml} and try again")
      end
    end

    # The global config for the CLI
    # @return [Hash] the current configuration
    def self.config
      @config ||= {}
    end

    # Clears the global configuration
    # @return [nil]
    def self.reset
      @config = {}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cabal-0.5.0 lib/cabal/cli.rb