Sha256: de4bea9e053bee47eb14e2648d11420e4bed76e08144c8c9d38c930b8abbd2c1

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

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]'
    }.freeze

    ##
    # @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

7 entries across 7 versions & 1 rubygems

Version Path
gemirro-1.2.0 lib/gemirro/cli.rb
gemirro-1.1.1 lib/gemirro/cli.rb
gemirro-1.1.0 lib/gemirro/cli.rb
gemirro-1.0.0 lib/gemirro/cli.rb
gemirro-0.16.0 lib/gemirro/cli.rb
gemirro-0.15.0 lib/gemirro/cli.rb
gemirro-0.14.0 lib/gemirro/cli.rb