Sha256: 0dd8d6e4737ea2ee28d632266b53580ed0abc346fc5b039f85fb4a696a4faf5a

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

# -*- coding: utf-8 -*-
module Gemirro
  # CLI mode
  module CLI
    ##
    # Hash containing the default Slop options.
    #
    # @return [Hash]
    #
    SLOP_OPTIONS = {
      strict: true,
      help: true,
      banner: 'Usage: gemirro [COMMAND] [OPTIONS]'
    }

    ##
    # @return [Slop]
    #
    def self.options
      @options ||= default_options
    end

    ##
    # Loads the specified configuration file or displays an error if it doesn't
    # exist.
    #
    # @param [String] config_file
    # @return [Gemirro::Configuration]
    #
    def self.load_configuration(config_file)
      config_file ||= Configuration.default_configuration_file
      config_file   = File.expand_path(config_file, Dir.pwd)
      config_file += '/config.rb' unless config_file.end_with?('.rb') ||
                                         !File.directory?(config_file)

      unless File.file?(config_file)
        abort "The configuration file #{config_file} does not exist"
      end

      require(config_file)
    end

    ##
    # @return [Slop]
    #
    def self.default_options
      Slop.new(SLOP_OPTIONS.dup) do
        separator "\nOptions:\n"

        on :v, :version, 'Shows the current version' do
          puts CLI.version_information
        end
      end
    end

    ##
    # Returns a String containing some platform/version related information.
    #
    # @return [String]
    #
    def self.version_information
      "gemirro v#{VERSION} on #{RUBY_DESCRIPTION}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gemirro-0.13.3 lib/gemirro/cli.rb
gemirro-0.13.2 lib/gemirro/cli.rb
gemirro-0.13.1 lib/gemirro/cli.rb