Parent

Commands::Install

Public Class Methods

new(base_command) click to toggle source
# 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

Public Instance Methods

determine_install_method() click to toggle source
# 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) click to toggle source
# 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
options() click to toggle source
# 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) click to toggle source
# 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_version() click to toggle source
# File lib/commands/plugin/commands.rb, line 448
def prompt_for_version
  ARGV.pop
  gets.strip.to_i
end
set_chosen_version(plugin) click to toggle source
# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.