Class: Commands::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/plugin/commands.rb

Constant Summary collapse

@@default_method =
:http

Instance Method Summary collapse

Constructor Details

#initialize(base_command) ⇒ Install

Returns a new instance of Install.



353
354
355
356
357
# File 'lib/commands/plugin/commands.rb', line 353

def initialize(base_command)
  @base_command = base_command
  @method = @@default_method
  @options = { :quiet => false, :revision => nil, :force => false, :force_http => false }
end

Instance Method Details

#determine_install_methodObject



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/commands/plugin/commands.rb', line 392

def determine_install_method
  return :http if @options[:force_http]
  best = @base_command.environment.best_install_method?
  @method = @@default_method if best == :http and @method == :export
  case
  when (best == :http and @method != :http)
    msg = "Cannot install using subversion because `svn' cannot be found in your PATH"
  when (best == :export and (@method != :export and @method != :http))
    msg = "Cannot install using #{@method} because this project is not under subversion."
  when (best != :externals and @method == :externals)
    msg = "Cannot install using externals because vendor/plugins is not under subversion."
  end
  if msg
    puts msg
    exit 1
  end
  @method
end

#get_version(versions) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/commands/plugin/commands.rb', line 434

def get_version(versions)
  prompt = "Multiple versions found, which version would you like to install?\n"
  index = 1
  versions.keys.sort.reverse.each{ |version| prompt << "#{index.to_s}. #{version}\n"; index = index.next }
  selected_version = nil
  while selected_version.nil?
    puts prompt
    print "> "
    selected_version = prompt_for_version
    selected_version = nil unless (1..versions.size).include?(selected_version.to_i)
  end
  return versions.keys.sort.reverse[selected_version-1]
end

#optionsObject



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/commands/plugin/commands.rb', line 359

def options
  OptionParser.new do |o|
    o.set_summary_indent('  ')
    o.banner =    "Usage: #{@base_command.script_name} install PLUGIN [PLUGIN [PLUGIN] ...]"
    o.define_head "Install one or more plugins."
    o.separator   ""
    o.separator   "Options:"
    o.on(         "-x", "--externals", 
                  "Use svn:externals to grab the plugin.", 
                  "Enables plugin updates and plugin versioning.") { |v| @method = :externals }
    o.on(         "-o", "--checkout",
                  "Use svn checkout to grab the plugin.",
                  "Enables updating but does not add a svn:externals entry.") { |v| @method = :checkout }
    o.on(         "-q", "--quiet",
                  "Suppresses the output from installation.",
                  "Ignored if -v is passed (./script/plugin -v install ...)") { |v| @options[:quiet] = true }
    o.on(         "-r REVISION", "--revision REVISION",
                  "Checks out the given revision from subversion.",
                  "Ignored if subversion is not used.") { |v| @options[:revision] = v }
    o.on(         "-f", "--force",
                  "Reinstalls a plugin if it's already installed.") { |v| @options[:force] = true }
    o.on(         "-c", "--svn",
                  "Modify files with subversion. (Note: svn must be in path)") { |v| @options[:svn] = true }
    o.on(         "-h", "--force-http",
                  "Forces download in HTTP mode") { |v| @options[:force_http] = true }
    o.on(         "--version",
                  "Install a specific version of a plugin") { |v| @options[:version] = v }
    o.separator   ""
    o.separator   "You can specify plugin names as given in 'plugin list' output or absolute URLs to "
    o.separator   "a plugin repository."
  end
end

#parse!(args) ⇒ Object



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/commands/plugin/commands.rb', line 411

def parse!(args)
  options.parse!(args)
  environment = @base_command.environment
  install_method = determine_install_method
  puts "Plugins will be installed using #{install_method}" if $verbose
  args.each do |name|
    plugin = ::Plugin.find(name)
    if @options[:version]
      if plugin.versions[@options[:version]].nil?
        puts "Invalid plugin version."
        exit 1
      end
    else
      set_chosen_version(plugin)
    end
    plugin.install(install_method, @options)
    environment.add_plugin_to_svn(plugin.name) if @options[:svn]
  end
#rescue
#  puts "Plugin not found: #{args.inspect}"
#  exit 1
end

#prompt_for_versionObject



448
449
450
451
# File 'lib/commands/plugin/commands.rb', line 448

def prompt_for_version
  ARGV.pop
  gets.strip.to_i
end

#set_chosen_version(plugin) ⇒ Object



453
454
455
456
457
458
459
# File 'lib/commands/plugin/commands.rb', line 453

def set_chosen_version(plugin)
  if plugin.versions.size > 1
    @options[:version] = get_version(plugin.versions)
  else
    @options[:version] = plugin.versions.keys.first
  end
end