2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/server'
|
|
|
|
|
|
|
|
class Gem::Commands::ServerCommand < Gem::Command
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super 'server', 'Documentation and gem repository HTTP server',
|
2010-04-22 04:24:42 -04:00
|
|
|
:port => 8808, :gemdir => [], :daemon => false
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
OptionParser.accept :Port do |port|
|
2018-11-21 05:20:47 -05:00
|
|
|
if port =~ /\A\d+\z/
|
2009-06-09 17:38:59 -04:00
|
|
|
port = Integer port
|
|
|
|
raise OptionParser::InvalidArgument, "#{port}: not a port number" if
|
|
|
|
port > 65535
|
|
|
|
|
|
|
|
port
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Socket.getservbyname port
|
2010-11-08 15:58:42 -05:00
|
|
|
rescue SocketError
|
2009-06-09 17:38:59 -04:00
|
|
|
raise OptionParser::InvalidArgument, "#{port}: no such named service"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option '-p', '--port=PORT', :Port,
|
2007-11-10 02:48:56 -05:00
|
|
|
'port to listen on' do |port, options|
|
|
|
|
options[:port] = port
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option '-d', '--dir=GEMDIR',
|
2010-04-22 04:24:42 -04:00
|
|
|
'directories from which to serve gems',
|
|
|
|
'multiple directories may be provided' do |gemdir, options|
|
|
|
|
options[:gemdir] << File.expand_path(gemdir)
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
add_option '--[no-]daemon', 'run as a daemon' do |daemon, options|
|
2007-11-10 02:48:56 -05:00
|
|
|
options[:daemon] = daemon
|
|
|
|
end
|
2010-02-21 21:52:35 -05:00
|
|
|
|
|
|
|
add_option '-b', '--bind=HOST,HOST',
|
|
|
|
'addresses to bind', Array do |address, options|
|
|
|
|
options[:addresses] ||= []
|
|
|
|
options[:addresses].push(*address)
|
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
|
2011-06-01 00:05:03 -04:00
|
|
|
add_option '-l', '--launch[=COMMAND]',
|
2011-01-18 19:08:49 -05:00
|
|
|
'launches a browser window',
|
|
|
|
"COMMAND defaults to 'start' on Windows",
|
|
|
|
"and 'open' on all other platforms" do |launch, options|
|
|
|
|
launch ||= Gem.win_platform? ? 'start' : 'open'
|
|
|
|
options[:launch] = launch
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def defaults_str # :nodoc:
|
|
|
|
"--port 8808 --dir #{Gem.dir} --no-daemon"
|
|
|
|
end
|
|
|
|
|
|
|
|
def description # :nodoc:
|
|
|
|
<<-EOF
|
|
|
|
The server command starts up a web server that hosts the RDoc for your
|
|
|
|
installed gems and can operate as a server for installation of gems on other
|
|
|
|
machines.
|
|
|
|
|
|
|
|
The cache files for installed gems must exist to use the server as a source
|
|
|
|
for gem installation.
|
|
|
|
|
|
|
|
To install gems from a running server, use `gem install GEMNAME --source
|
|
|
|
http://gem_server_host:8808`
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
You can set up a shortcut to gem server documentation using the URL:
|
|
|
|
|
|
|
|
http://localhost:8808/rdoc?q=%s - Firefox
|
|
|
|
http://localhost:8808/rdoc?q=* - LaunchBar
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2012-11-29 01:52:18 -05:00
|
|
|
options[:gemdir] = Gem.path if options[:gemdir].empty?
|
2007-11-10 02:48:56 -05:00
|
|
|
Gem::Server.run options
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|