class GemLookup::Flags

Public Class Methods

supported() click to toggle source

Returns the supported flags. @return [Hash] the supported flags.

# File lib/gem_lookup/flags.rb, line 10
def supported
  {
    help:    { matches: %w[-h --help], desc: 'Display the help screen.' },
    version: { matches: %w[-v --version], desc: 'Display version information.' },
    json:    { matches: %w[-j --json], desc: 'Bulk the output results as raw JSON.' },
    wordy:   { matches: %w[-w --wordy], desc: 'Stream the output using only words.' }
  }
end
supported?(type, flags: []) click to toggle source

Checks to see if any flags passed in match those defined by the type. @param type [Symbol] the type of flag (`:help`, `:version`, etc). @param flags [Array] an array that may or may not contain a supported flag. @return [Boolean] whether the flags passed in contain a flag supported by type.

# File lib/gem_lookup/flags.rb, line 23
def supported?(type, flags: [])
  return false if type.nil?
  return false if flags.empty?

  type = type.to_sym
  return false unless supported.key? type

  supported[type][:matches].each do |flag|
    return true if flags.include? flag
  end

  false
end
unsupported(flags:) click to toggle source

Outputs the unsupported flags and exits with a code of 1. @param flags [Array] the list of unsupported flags.

# File lib/gem_lookup/flags.rb, line 39
def unsupported(flags:)
  flags = flags.compact.reject(&:empty?)
  return false unless flags.any?

  raise Errors::UnsupportedFlag, flags.first if flags.size == 1

  raise Errors::UnsupportedFlags, flags.join(', ')
end