module Polisher::CLI

Public Class Methods

conf() click to toggle source
# File lib/polisher/cli/conf.rb, line 10
def self.conf
  @conf ||= {}
end

Public Instance Methods

clear() click to toggle source
# File lib/polisher/cli/status.rb, line 10
def clear
  puts `clear`
end
conf() click to toggle source
# File lib/polisher/cli/conf.rb, line 14
def conf
  CLI.conf
end
conf_gem?() click to toggle source
# File lib/polisher/cli/sources.rb, line 62
def conf_gem?
  conf[:gemname] || conf[:gemspec]
end
conf_gemfile?() click to toggle source
# File lib/polisher/cli/sources.rb, line 66
def conf_gemfile?
  !conf[:gemfile].nil?
end
conf_source() click to toggle source
# File lib/polisher/cli/sources.rb, line 70
def conf_source
  if conf[:gemname]
    name = conf[:gemname]
    if conf[:gemversion]
      version = conf[:gemversion]
      Polisher::Gem.from_rubygems(name, version)

    elsif !RELATIVE_SPECIFIERS.include?(conf[:matching])
      target = conf[:matching]
      begin
      Polisher::Gem.latest_in_target(name, target)
      rescue
        Polisher::Gem.retrieve(name)
      end

    else
      Polisher::Gem.retrieve(name)
    end

  elsif conf[:gemspec]
    Polisher::Gem.from_gemspec(conf[:gemspec])
  
  elsif conf[:gemfile]
    gemfile = nil

    begin
      gemfile = Polisher::Gemfile.parse(conf[:gemfile], :groups => conf[:groups])
    rescue => e
      puts "Runtime err #{e}".red
      exit 1
    end

    gemfile
  end
end
configure_targets(conf) click to toggle source
# File lib/polisher/cli/targets.rb, line 77
def configure_targets(conf)
  if conf[:check_koji]
    require 'polisher/targets/koji'
    Polisher::Koji.koji_url conf[:check_koji]   if conf[:check_koji].is_a?(String)
    Polisher::Koji.koji_tag conf[:koji_tag]     if conf[:koji_tag]
    Polisher::Koji.package_prefix conf[:prefix] if conf[:prefix]
  end

  # TODO other target config
end
default_conf() click to toggle source
# File lib/polisher/cli/default.rb, line 10
def default_conf
  { :log_level => :info }
end
default_options(option_parser) click to toggle source
# File lib/polisher/cli/default.rb, line 14
def default_options(option_parser)
  option_parser.on('-h', '--help', 'Display this help screen') do
    puts option_parser
    exit
  end

  option_parser.on('-l', '--log-level [level]', 'Set the log level') do |level|
    conf[:log_level] = level.intern
  end
end
elipses_delay() click to toggle source
# File lib/polisher/cli/status.rb, line 18
def elipses_delay
  conf[:elipses_delay] ||= 1
end
end_waiting() click to toggle source
# File lib/polisher/cli/status.rb, line 44
def end_waiting
  return unless @waiting_thread
  @term_waiting = true
  @waiting_thread.join
end
format_dep(dep, resolved_dep) click to toggle source
# File lib/polisher/cli/format.rb, line 45
def format_dep(dep, resolved_dep)
  if @format.nil?
    "\n #{dep.to_s.green.bold} (#{resolved_dep.version})"
  elsif @format == 'xml'
    "<#{dep.name}>#{dep.requirement}/#{resolved_dep.version}</#{dep.name}>"
  elsif @format == 'json'
    "'#{dep.name}':'#{dep.requirement}/#{resolved_dep.version}'"
  end
end
format_end(closer) click to toggle source
# File lib/polisher/cli/format.rb, line 25
def format_end(closer)
  if @format.nil?
    "\n"
  elsif @format == 'xml'
    "\n</#{closer}>"
  elsif @format == 'json'
    "\n}"
  end
end
format_missing_dep(dep) click to toggle source
# File lib/polisher/cli/format.rb, line 35
def format_missing_dep(dep)
  if @format.nil?
    "\n #{dep.to_s.red.bold}"
  elsif @format == 'xml'
    "<#{dep.name}>#{dep.requirement}</#{dep.name}>"
  elsif @format == 'json'
    "'#{dep.name}':'#{dep.requirement}'"
  end
end
format_tgt(tgt) click to toggle source
# File lib/polisher/cli/format.rb, line 71
def format_tgt(tgt)
  if @format.nil?
    " #{tgt.to_s.red.bold}"
  elsif @format == 'xml'
    "<#{tgt}/>"
  elsif @format == 'json'
    "'#{tgt}':null,"
  end
end
format_tgt_with_versions(tgt, versions) click to toggle source
# File lib/polisher/cli/format.rb, line 89
def format_tgt_with_versions(tgt, versions)
  if @format.nil?
    " #{tgt.to_s.green.bold}: #{versions.join(', ').yellow}"
  elsif @format == 'xml'
    "<#{tgt}>#{versions.join(', ')}</#{tgt}>"
  elsif @format == 'json'
    "'#{tgt}':['#{versions.join('\', \'')}'],"
  end
end
format_title(title) click to toggle source
# File lib/polisher/cli/format.rb, line 15
def format_title(title)
  if @format.nil?
    title.to_s.blue.bold + ' '
  elsif @format == 'xml'
    "<#{title}>"
  elsif @format == 'json'
    "'#{title}':{"
  end
end
format_unknown_tgt(tgt) click to toggle source
# File lib/polisher/cli/format.rb, line 81
def format_unknown_tgt(tgt)
  if @format.nil?
    "#{tgt.to_s.red.bold}: " + "unknown".yellow
  else
    format_tgt("#{tgt} (unknown)")
  end
end
gem_dependency_checker_conf() click to toggle source
# File lib/polisher/cli/bin/gem_dependency_checker.rb, line 11
def gem_dependency_checker_conf
  conf.merge!({:format => nil}).merge!(default_conf)
                               .merge!(targets_conf)
                               .merge!(sources_conf)
end
gem_dependency_checker_option_parser() click to toggle source
# File lib/polisher/cli/bin/gem_dependency_checker.rb, line 23
def gem_dependency_checker_option_parser
  OptionParser.new do |opts|
    default_options                opts
    sources_options                opts
    targets_options                opts
    gem_dependency_checker_options opts
  end
end
gem_dependency_checker_options(option_parser) click to toggle source
# File lib/polisher/cli/bin/gem_dependency_checker.rb, line 17
def gem_dependency_checker_options(option_parser)
  option_parser.on("--format val", 'Format which to render output') do |f|
    conf[:format] = f
  end
end
header() click to toggle source
# File lib/polisher/cli/bin/gem_dependency_checker.rb, line 32
def header
  if @format == 'xml'
    '<dependencies>'
  elsif @format == 'json'
    '{'
  end
end
last_dep() click to toggle source
# File lib/polisher/cli/format.rb, line 122
def last_dep # XXX
  format_end(@last_dep) unless @last_dep.nil?
end
last_gem() click to toggle source
# File lib/polisher/cli/format.rb, line 126
def last_gem # XXX
  format_end(@last_gem) unless @last_gem.nil?
end
num_elipses() click to toggle source
# File lib/polisher/cli/status.rb, line 14
def num_elipses
  conf[:num_elipses] ||= 5
end
pretty_dep(gem, dep, resolved_dep) click to toggle source
# File lib/polisher/cli/format.rb, line 55
def pretty_dep(gem, dep, resolved_dep)
  pretty = ''

  # XXX little bit hacky but works for now
  @last_gem ||= nil
  if @last_gem != gem
    pretty += format_end(@last_dep.name) unless @last_gem.nil?
    pretty += format_title(gem.is_a?(Gemfile) ? "Gemfile" : "#{gem.name} #{gem.version}")
    @last_gem = gem
  end

  pretty += resolved_dep.nil? ? format_missing_dep(dep) : format_dep(dep, resolved_dep)
  @last_dep = dep
  pretty
end
pretty_tgt(dep, tgt, versions) click to toggle source
# File lib/polisher/cli/format.rb, line 99
def pretty_tgt(dep, tgt, versions)
  pretty = ''

  @last_dep ||= nil
  if @last_dep != dep
    pretty += format_end(@last_dep) unless @last_dep.nil?
    pretty += format_title(dep)
    @last_dep = dep
  end

  if versions.blank? || (versions.size == 1 && versions.first.blank?)
    pretty += format_tgt(tgt)

  elsif versions.size == 1 && versions.first == :unknown
    pretty += format_unknown_tgt(tgt)

  else
    pretty += format_tgt_with_versions(tgt, versions)
  end

  pretty
end
print_dep(dep, tgt, versions) click to toggle source
print_deps(conf) click to toggle source
print_gem_deps(gem) click to toggle source
print_gemfile_deps(gemfile) click to toggle source
print_header() click to toggle source
set_format(conf) click to toggle source
# File lib/polisher/cli/format.rb, line 11
def set_format(conf)
  @format = conf[:format]
end
set_targets(conf) click to toggle source
# File lib/polisher/cli/targets.rb, line 64
def set_targets(conf)
  targets = []
  require 'polisher/adaptors/version_checker'
  targets << :gem    if conf[:check_gem]
  targets << :koji   if conf[:check_koji]
  targets << :fedora if conf[:check_fedora]
  targets << :git    if conf[:check_git]
  targets << :yum    if conf[:check_yum]
  targets << :bodhi  if conf[:check_bodhi]
  targets  = Polisher::VersionChecker.targets        if targets.empty?
  Polisher::VersionChecker.check targets
end
sources_conf() click to toggle source
# File lib/polisher/cli/sources.rb, line 13
def sources_conf
  { :gemfile    => './Gemfile',
    :gemspec    => nil,
    :gemname    => nil,
    :gemversion => nil,
    :groups     => [],
    :devel_deps => false }
end
sources_options(option_parser) click to toggle source
# File lib/polisher/cli/sources.rb, line 22
def sources_options(option_parser)
  option_parser.on('--gemfile file', 'Location of the gemfile to parse') do |g|
    conf[:gemfile] = g
  end

  option_parser.on('--group gemfile_groups', 'Gemfile groups (may be specified multiple times)') do |g|
    conf[:groups] << g
  end

  option_parser.on('--gemspec file', 'Location of the gemspec to parse') do |g|
    conf[:gemspec] = g
  end

  option_parser.on('--gem name', 'Name of the rubygem to check') do |g|
    conf[:gemname] = g
  end

  option_parser.on('-v', '--version [version]', 'Version of gem to check') do |v|
    conf[:gemversion] = v
  end

  option_parser.on('--[no-]devel', 'Include development dependencies') do |d|
    conf[:devel_deps] = d
  end
end
specifier_conf() click to toggle source
# File lib/polisher/cli/specifier.rb, line 12
def specifier_conf
  { :matching   => LATEST_SPECIFIER }
end
specifier_opts(option_parser) click to toggle source
# File lib/polisher/cli/specifier.rb, line 16
def specifier_opts(option_parser)
  option_parser.on('--latest', 'Check latest matching version of gem') do
    conf[:matching] = LATEST_SPECIFIER
  end

  option_parser.on('--earliest', 'Check earliest matching version of gem') do
    conf[:matching] = EARLIEST_SPECIFIER
  end

  option_parser.on('--target [tgt]', 'Check version of gem in target') do |t|
    conf[:matching] = t
  end
end
targets_conf() click to toggle source
# File lib/polisher/cli/targets.rb, line 10
def targets_conf
  { :check_fedora   => false,
    :check_git      => false,
    :check_koji     => false,
    :check_rhn      => false,
    :check_yum      => false,
    :check_bugzilla => false,
    :check_errata   => false,
    :check_bodhi    => false,
    :prefix         => nil }
end
targets_options(option_parser) click to toggle source
# File lib/polisher/cli/targets.rb, line 22
def targets_options(option_parser)
  option_parser.on('-p', '--prefix prefix', 'Prefix to append to gem name') do |p|
    conf[:prefix] = p
  end

  option_parser.on('-f', '--[no-]fedora', 'Check fedora for packages') do |f|
    conf[:check_fedora] = f
  end

  option_parser.on('-g', '--git [url]', 'Check git for packages') do |g|
    conf[:check_git] = g || "git://pkgs.fedoraproject.org/"
  end

  option_parser.on('-k', '--koji [url]', 'Check koji for packages') do |k|
    conf[:check_koji] = k || true
  end

  option_parser.on('-t', '--koji-tag tag', 'Koji tag to query') do |t|
    conf[:koji_tag] = t
  end

  option_parser.on('-b', '--bodhi [url]', 'Check Bodhi for packages') do |r|
    conf[:check_bodhi] = r || 'https://admin.fedoraproject.org/updates/'
  end

  option_parser.on('--rhn [url]', 'Check RHN for packages') do |r|
    conf[:check_rhn] = r || 'TODO'
  end

  option_parser.on('-y', '--yum', 'Check yum for packages') do |y|
    conf[:check_yum] = y
  end

  option_parser.on('-b', '--bugzilla', 'Check bugzilla for bugs filed against package') do |b|
    conf[:check_bugzilla] = b
  end

  option_parser.on('-e', '--errata [url]', 'Check packages filed in errata') do |e|
    conf[:check_errata] = e || nil
  end
end
validate_sources() click to toggle source
# File lib/polisher/cli/sources.rb, line 48
def validate_sources
  if conf[:gemfile].nil? &&
     conf[:gemspec].nil? &&
     conf[:gemname].nil?
  
     if File.exists?('./Gemfile')
       conf[:gemfile] = './Gemfile'
     else
       puts "Valid Gemfile, GemSpec, or Gem must be specified".bold.red
       exit 1
     end
  end
end
waiting(args={}) click to toggle source
# File lib/polisher/cli/status.rb, line 26
def waiting(args={})
  waiting_msg(args[:msg]) if args.key?(:msg)
  color = args[:color] || :black

  @term_waiting = false
  @waiting_thread = Thread.new(conf) { |conf|
    until @term_waiting
      clear
      print conf[:wait_msg].send(color) if conf.key?(:wait_msg)
      0.upto(num_elipses) {
        print '.'.send(color)
        sleep elipses_delay
      }
      puts
    end
  }
end
waiting_msg(msg) click to toggle source
# File lib/polisher/cli/status.rb, line 22
def waiting_msg(msg)
  conf[:wait_msg] = msg
end