add better help to the hudson.war executable.

This commit is contained in:
Charles Lowell 2011-01-05 07:58:20 -06:00
parent 102f1d4e8f
commit 9eafe638ea
3 changed files with 90 additions and 19 deletions

View File

@ -21,7 +21,7 @@ In addition to the war file long with the The hudson-war gem comes with an exec
Without any arguments, it returns the location of the hudson warfile itself:
$ hudson.war location
/path/to/hudson.war
/Users/cowboyd/.rvm/gems/ruby-1.8.7-p174@hudson.war/gems/hudson-war-1.391/lib/hudson/hudson.war
It can unpack itself to a given directory. This is useful if you want to extract certain assets such as classfiles, annotations, configurations from it.
@ -29,7 +29,7 @@ It can unpack itself to a given directory. This is useful if you want to extract
It can copy itself anywhere
legolas: cowboyd$ hudson.war cp tmp
$ hudson.war cp tmp
copied /Users/cowboyd/.rvm/gems/ruby-1.8.7-p174@hudson.war/gems/hudson-war-1.391/lib/hudson/hudson.war -> tmp
Or if you want the classpath:
@ -38,3 +38,8 @@ Or if you want the classpath:
legolas:hudson.war cowboyd$ hudson.war classpath
/Users/cowboyd/.hudson/wars/1.391/WEB-INF/lib/hudson-core-1.391.jar
You can even run a test server with your shiny hudson war file.
$ hudson.war server

View File

@ -1,20 +1,89 @@
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require File.expand_path(File.dirname(__FILE__) + '/../lib/hudson/war')
war = Hudson::War
parser = OptionParser.new
parser.on("-v", "--version", String, "Use this version of hudson") do |version|
puts war::VERSION
exit(1)
options = OpenStruct.new({
:home => File.join(ENV['HOME'], ".hudson", "server"),
:port => 3001,
:control => 3002,
:daemon => false,
:kill => false
})
parser = OptionParser.new
parser.banner = "Usage: hudson.war server [options]"
parser.on("--home DIR", String, "use this directory to store server data") {|dir| options.home = dir}
parser.on("-p", "--port PORT", Integer, "run hudson server on this port") {|port| options.port = port}
parser.on("-c", "--control PORT", Integer, "set the shutdown/control port") {|control| options.control = control}
parser.on("--daemon") {options.daemon = true}
parser.on("-k", "--kill") {options.kill = true}
parser.on("--logfile PATH", String, "redirect log messages to this file") {|path| options.logfile = path}
help = proc do |cmd|
help = Help.new(parser)
if cmd && help.respond_to?(cmd)
puts help.send(cmd)
else
puts "usage: hudson.war COMMAND [OPTIONS]"
puts " hudson.war help command"
puts " hudson.war version"
puts " hudson.war unpack DESTINATION"
puts " hudson.war classpath"
puts " hudson.war cp DESTINATION"
puts " hudson.war server [OPTIONS]"
puts ""
end
end
parser.parse(ARGV)
class Help
def initialize(server_options)
@server_options = server_options
end
def help
<<-HERE
Usage: hudson.war help COMMAND
shows help for the specified command
HERE
end
def version
<<-HERE
Usage: hudson.war version
displays the version of hudson represented by this war
HERE
end
def unpack
<<-HERE
Usage: hudson.war unpack DESTINATION
unpack the hudson war to directory at DESTINATION
HERE
end
def classpath
<<-HERE
Usage: hudson.war classpath
return a classpath for hudson core which can be used for a javac invocation
HERE
end
def cp
<<-HERE
Usage: hudson.war cp PATH
copy the hudson.war file to PATH
HERE
end
def server
@server_options.to_s
end
end
war = Hudson::War
case cmd = ARGV.shift
when "version", "-v", "--version"
puts war::VERSION
exit
when 'unpack'
dest = ARGV.first
war.unpack(dest)
@ -23,7 +92,12 @@ when 'classpath'
when 'cp'
dest = ARGV.first
war.cp dest
when 'server'
parser.parse(ARGV)
war.server(options)
when "help", "-h", "--help"
help[ARGV.first]
else
puts war::LOCATION
help[nil]
end

View File

@ -21,15 +21,7 @@ module Hudson
output << "copied #{LOCATION} -> #{dest}\n"
end
# desc "server [options]", "run a hudson server"
# method_option :home, :desc => "use this directory to store server data", :type => :string, :default => File.join(ENV['HOME'], ".hudson", "server"), :banner => "PATH"
# method_option :port, :desc => "run hudson server on this port", :type => :numeric, :default => 3001, :aliases => "-p"
# method_option :control, :desc => "set the shutdown/control port", :type => :numeric, :default => 3002, :aliases => "-c"
# method_option :daemon, :desc => "fork into background and run as a daemon", :type => :boolean, :default => false
# method_option :kill, :desc => "send shutdown signal to control port", :type => :boolean, :aliases => "-k"
# method_option :logfile, :desc => "redirect log messages to this file", :type => :string, :banner => "PATH"
def server(output, options)
def server(options, output = $stdout)
home = options.home || File.join(ENV['HOME'], ".hudson", "server")
port = options.port.to_i || 3001
control = options.control.to_i || 3002
@ -45,7 +37,7 @@ module Hudson
else
javatmp = File.join(home, "javatmp")
FileUtils.mkdir_p javatmp
ENV['HUDSON_HOME'] = serverhome
ENV['HUDSON_HOME'] = home
cmd = ["java", "-Djava.io.tmpdir=#{javatmp}", "-jar", LOCATION]
cmd << "--daemon" if daemon
cmd << "--logfile=#{File.expand_path(logfile)}" if logfile