class Travis::CLI::Repos

def attributes(repo)

def attributes(repo)
  { 'active' => repo.active?, 'admin' => repo.admin?, 'push' => repo.push?, 'pull' => repo.pull? }
end

def match?(string)

def match?(string)
  return true if match.nil?
  flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
  flags |= File::FNM_EXTGLOB if defined? File::FNM_EXTGLOB
  File.fnmatch?(match, string, flags)
end

def repositories

def repositories
  @repositories ||= begin
    repos = session.hooks.concat(user.repositories).uniq
    session.preload(repos).sort_by(&:slug).select do |repo|
      next false unless match? repo.slug
      next false unless active.nil? || (repo.active?    == active)
      next false unless owner.nil?  || (repo.owner_name == owner)
      next false unless name.nil?   || (repo.name       == name)
      next false unless admin.nil?  || (repo.admin?     == admin)
      true
    end
  end
end

def run

def run
  repositories.each do |repo|
    next say(repo.slug) unless interactive?
    state_color = repo.active? ? :green : :yellow
    say "#{color(repo.slug, [:bold, state_color])} "
    say color('(' << attributes(repo).map { |n, v| "#{n}: #{v ? 'yes' : 'no'}" }.join(', ') << ')', state_color)
    description = repo.description.lines.first.chomp unless repo.description.to_s.empty?
    say "Description: #{description || '???'}"
    empty_line unless repo == repositories.last
  end
end