Sha256: 5026315ce91a7561d4af6d16a5896c922d4c32061c97312ec36b16c22a8595b8

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

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)

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

      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-1.5.0 lib/gemirro/cli.rb
gemirro-1.4.0 lib/gemirro/cli.rb
gemirro-1.3.0 lib/gemirro/cli.rb