class Rubygems::Manifest::CLI

Public Class Methods

start() click to toggle source
# File lib/rubygems/manifest/cli.rb, line 7
def self.start
  new.start
end

Public Instance Methods

color(str, n) click to toggle source
# File lib/rubygems/manifest/cli.rb, line 87
def color(str, n)
  "\e[#{n}m#{str}\e[0m"
end
green(str) click to toggle source
# File lib/rubygems/manifest/cli.rb, line 75
def green(str)
  color(str, 32)
end
manifest() click to toggle source
# File lib/rubygems/manifest/cli.rb, line 71
def manifest
  @manifest ||= Rubygems::Manifest.new
end
red(str) click to toggle source
# File lib/rubygems/manifest/cli.rb, line 79
def red(str)
  color(str, 31)
end
start() click to toggle source
# File lib/rubygems/manifest/cli.rb, line 11
def start
  opts = OptionParser.new
  opts.banner = "Usage: manifest [commands] [options]\n"
  opts.banner << "\n"
  opts.banner << "Commands:\n"
  opts.banner << ("    save".ljust(37))  + "Save to Manifest.txt [default]\n"
  opts.banner << ("    check".ljust(37)) + "Check Manifest.txt\n"
  opts.banner << ("    files".ljust(37)) + "Print files\n"
  opts.banner << ("    executables".ljust(37)) + "Print executables\n"
  opts.banner << ("    test-files".ljust(37)) + "Print all test files\n"
  opts.banner << ("    tests".ljust(37)) + "Print tests\n"

  opts.banner << "\n"
  opts.banner << "Options:\n"

  opts.on("-v", "--version", "Print version") do
    puts Rubygems::Manifest::VERSION
    exit(0)
  end

  opts.parse!

  case ARGV[0]
  when 'save'
    manifest.save

    if manifest.files.none?
      puts yellow("Manifest is empty")
    else
      puts manifest.files
      $stderr.puts green("Manifest is saved successfully")
    end
  when 'check'
    begin
      manifest.check

      if manifest.files.none?
        puts yellow("Manifest is empty")
      else
        puts manifest.files
        $stderr.puts green("Manifest is valid")
      end
    rescue => e
      puts e.message
      $stderr.puts red("Manifest is invalid")
      exit 1
    end
  when 'files'
    puts manifest.files
  when 'executables'
    puts manifest.executables
  when 'test-files'
    puts manifest.test_files
  when 'tests'
    puts manifest.tests
  else
    puts opts
  end
end
yellow(str) click to toggle source
# File lib/rubygems/manifest/cli.rb, line 83
def yellow(str)
  color(str, 33)
end