Class: Gem::Commands::BootstrapCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
CommandOptions, Gem::Commands, GemRelease, Helpers
Defined in:
lib/rubygems/commands/bootstrap_command.rb

Constant Summary collapse

DEFAULTS =
{
  :gemspec  => true,
  :strategy => 'git',
  :scaffold => true,
  :github   => false,
  :quiet    => false
}

Constants included from GemRelease

GemRelease::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BootstrapCommand

Returns a new instance of BootstrapCommand.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubygems/commands/bootstrap_command.rb', line 18

def initialize(options = {})
  super 'bootstrap', 'Bootstrap a new gem source repository', DEFAULTS.merge(options)

  option :gemspec,  '-g', 'Generate a .gemspec'
  option :scaffold, '-s', 'Scaffold lib/[gem_name]/version.rb README test/'
  option :strategy, '-f', 'Strategy for collecting files [glob|git] in .gemspec'
  option :github,   '-h', 'Bootstrap a git repo, create on github and push'
  option :quiet,    '-q', 'Do not output status messages'

  @arguments = "gemname - option name of the gem, will use the current directory if not specified"
  @usage = "#{program_name} [gemname]"
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



16
17
18
# File 'lib/rubygems/commands/bootstrap_command.rb', line 16

def arguments
  @arguments
end

#usageObject (readonly)

Returns the value of attribute usage.



16
17
18
# File 'lib/rubygems/commands/bootstrap_command.rb', line 16

def usage
  @usage
end

Instance Method Details

#create_file(template) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/rubygems/commands/bootstrap_command.rb', line 60

def create_file(template)
  if File.exists?(template.filename)
    say "Skipping #{template.filename}: already exists" unless quiet?
  else
    say "Creating #{template.filename}" unless quiet?
    template.write
  end
end

#create_libObject



56
57
58
# File 'lib/rubygems/commands/bootstrap_command.rb', line 56

def create_lib
  `mkdir -p lib test`
end

#create_repoObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rubygems/commands/bootstrap_command.rb', line 74

def create_repo
  options = { :login => github_user, :token => github_token, :name  => gem_name }
  options = options.map { |name, value| "-F '#{name}=#{value}'" }.join(' ')

  say 'Staging files'
  `git add .`

  say 'Creating initial commit'
  `git commit -m 'initial commit'`

  say "Adding remote origin [email protected]:#{github_user}/#{gem_name}.git"
  `git remote add origin [email protected]:#{github_user}/#{gem_name}.git`

  say 'Creating repository on Github'
  silence { `curl #{options} http://github.com/api/v2/yaml/repos/create` }

  say 'Pushing to Github'
  `git push origin master`
end

#executeObject



31
32
33
34
35
36
37
38
# File 'lib/rubygems/commands/bootstrap_command.rb', line 31

def execute
  in_bootstrapped_dir do
    write_scaffold if options[:scaffold]
    write_gemspec  if options[:gemspec]
    init_git       if options[:github] || options[:args] # safe to 'git init' in new dir
    create_repo    if options[:github]
  end
end

#init_gitObject



69
70
71
72
# File 'lib/rubygems/commands/bootstrap_command.rb', line 69

def init_git
  say 'Initializing git repository'
  `git init`
end

#write_gemspecObject



40
41
42
# File 'lib/rubygems/commands/bootstrap_command.rb', line 40

def write_gemspec
  GemspecCommand.new(:quiet => quiet?, :strategy => options[:strategy]).execute
end

#write_scaffoldObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubygems/commands/bootstrap_command.rb', line 44

def write_scaffold
  say 'scaffolding ...' unless quiet?

  create_file Template.new('gitignore', :filename => '.gitignore')
  create_file Template.new('README.md')
  create_file Template.new('LICENSE', :year => Time.now.year, :author => user_name, :email => user_email)
  create_file Template.new('Gemfile')
  create_file Template.new('Rakefile')
  create_file Template.new('test/test_helper.rb')
  create_file VersionTemplate.new(options)
end