1require 'rubygems/command'
2require 'rubygems/package'
3
4class Gem::Commands::BuildCommand < Gem::Command
5
6  def initialize
7    super 'build', 'Build a gem from a gemspec'
8
9    add_option '--force', 'skip validation of the spec' do |value, options|
10      options[:force] = true
11    end
12  end
13
14  def arguments # :nodoc:
15    "GEMSPEC_FILE  gemspec file name to build a gem for"
16  end
17
18  def usage # :nodoc:
19    "#{program_name} GEMSPEC_FILE"
20  end
21
22  def execute
23    gemspec = get_one_gem_name
24
25    if File.exist? gemspec then
26      spec = Gem::Specification.load gemspec
27
28      if spec then
29        Gem::Package.build spec, options[:force]
30      else
31        alert_error "Error loading gemspec. Aborting."
32        terminate_interaction 1
33      end
34    else
35      alert_error "Gemspec file not found: #{gemspec}"
36      terminate_interaction 1
37    end
38  end
39
40end
41
42