src/cli/openstudio_cli.rb
# Executes the RubyGems gem install process, using the RubyGems options
#
# @param [Array] sub_argv Options passed to the gem_install command from the user input
# @return [Fixnum] Return status
#
Executes the RubyGems gem install process, using the RubyGems options
Executes the RubyGems gem install process using the RubyGems options
def execute(sub_argv)
    require 'rubygems'
    require 'rubygems/commands/install_command'
    $logger.info "InstallGem, sub_argv = #{sub_argv}"
    options = {}
    opts = OptionParser.new do |o|
      o.banner = 'Usage: openstudio gem_install gem_name gem_version'
      o.separator ''
      o.separator 'Options:'
      o.separator ''
    end
    argv = parse_options(opts, sub_argv)
    return 0 if argv == nil
    $logger.debug("InstallGem command: #{argv.inspect} #{options.inspect}")
    if argv == []
      $logger.error 'No gem name provided'
      return 1
    end
    gem_name = argv[0]
    gem_version = argv[1]
    cmd = Gem::Commands::InstallCommand.new
    cmd.handle_options ["--no-ri", "--no-rdoc", 'rake', '--version', '0.9']  
    ARGV.clear
    ARGV << gem_name
    if gem_version
      ARGV << '--version'
      ARGV << gem_version
    end
    $logger.info "Installing gem to #{ENV['GEM_HOME']}"
    begin
      cmd.execute
    rescue => e
      $logger.error "Error installing gem: #{e.message} in #{e.backtrace.join("\n")}"
      exit e.exit_code
    rescue LoadError => e
      $logger.error "gem_install command not yet implemented, requires fiddle extension"
      return 1
    end
    $logger.info 'The gem was successfully installed'
    0
  end
def execute ( sub_argv ) require 'rubygems' require 'rubygems/commands/install_command' $logger . info "InstallGem, sub_argv = #{sub_argv}" options = { } opts = OptionParser . new do | o | o . banner = 'Usage: openstudio gem_install gem_name gem_version' o . separator '' o . separator 'Options:' o . separator '' end argv = parse_options ( opts , sub_argv ) return 0 if argv == nil $logger . debug ( "InstallGem command: #{argv.inspect} #{options.inspect}" ) if argv == [ ] $logger . error 'No gem name provided' return 1 end gem_name = argv [ 0 ] gem_version = argv [ 1 ] cmd = Gem :: Commands :: InstallCommand . new cmd . handle_options [ "--no-ri" , "--no-rdoc" , 'rake' , '--version' , '0.9' ] ARGV . clear ARGV << gem_name if gem_version ARGV << '--version' ARGV << gem_version end $logger . info "Installing gem to #{ENV['GEM_HOME']}" begin cmd . execute rescue => e $logger . error "Error installing gem: #{e.message} in #{e.backtrace.join("\n")}" exit e . exit_code rescue LoadError => e $logger . error "gem_install command not yet implemented, requires fiddle extension" return 1 end $logger . info 'The gem was successfully installed' 0 end
Executes the RubyGems gem install process, using the RubyGems options
Executes the RubyGems gem install process using the RubyGems options
# Parse the options # Parse the options # or omit --version and the following option to install the latest # DLM: gem install tries to load a Windows dll to access network functionality in win32/resolv # Ruby must be built with libffi to enable fiddle extension to enable win32 extension #$logger.error "#{e.message} in #{e.backtrace.join("\n")}"
None
Fixnum
sub_argv
<not_specific>
<not_specific>
sub_argv Options passed to the gem_install command from the user input
sub_argv Options passed to the gem_install command from the user input