Guest User

Untitled

a guest
Jun 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'optparse'
  4. require 'webrick'
  5. include WEBrick
  6.  
  7. # WEBrickを起動する際のオプションのデフォルト値
  8. WebrickOptions = {
  9. :Port => 8000,
  10. :DocumentRoot => Dir::pwd,
  11. }
  12.  
  13. OptionParser.new do |opt|
  14. # パース方法を設定する
  15. # オプションが指定されていた場合にブロックが評価される
  16. opt.on('-p', '--Port N', Integer) { |v| WebrickOptions[:Port] = v }
  17. opt.on('-d', '--DocumentRoot PATH') { |v| WebrickOptions[:DocumentRoot] = v }
  18.  
  19. # 実際にパースを行う
  20. opt.parse!(ARGV)
  21. end
  22.  
  23. # WEBrickを起動する
  24. s = HTTPServer.new(WebrickOptions)
  25. trap("INT") { s.shutdown }
  26. s.start
Add Comment
Please, Sign In to add comment