class Coveralls::CommandLine

def ensure_can_run_locally!

def ensure_can_run_locally!
  config = Coveralls::Configuration.configuration
  if config[:repo_token].nil?
    Coveralls::Output.puts "Coveralls cannot run locally because no repo_secret_token is set in .coveralls.yml", :color => "red"
    Coveralls::Output.puts "Please try again when you get your act together.", :color => "red"
    return false
  end
  true
end

def last

def last
  open_token_based_url "https://coveralls.io/repos/%@/last_build"
end

def open

def open
  open_token_based_url "https://coveralls.io/repos/%@"
end

def open_token_based_url url

def open_token_based_url url
  config = Coveralls::Configuration.configuration
  if config[:repo_token]
    url = url.gsub("%@", config[:repo_token])
    `open #{url}`
  else
    Coveralls::Output.puts "No repo_token configured."
  end
end

def push

def push
  return unless ensure_can_run_locally!
  ENV["COVERALLS_RUN_LOCALLY"] = "true"
  cmds = "bundle exec rake"
  if File.exist?('.travis.yml')
    cmds = YAML.load_file('.travis.yml')["script"] || cmds rescue cmds
  end
  cmds.each { |cmd| system cmd }
  ENV["COVERALLS_RUN_LOCALLY"] = nil
end

def report

def report
  ENV["COVERALLS_NOISY"] = "true"
  exec "bundle exec rake"
  ENV["COVERALLS_NOISY"] = nil
end

def service

def service
  open_token_based_url "https://coveralls.io/repos/%@/service"
end

def version

def version
  Coveralls::Output.puts Coveralls::VERSION
end