Advertisement
Guest User

Untitled

a guest
Jul 31st, 2017
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
  4. # All files in this distribution are subject to the terms of the Ruby license.
  5.  
  6. require 'ramaze'
  7.  
  8. usage = %{
  9. Usage: ramaze [switches] startfile [arguments]
  10. -a, --adapter=ADAPTER select an adapter [mongrel|webrick]
  11. -m, --mongrel use mongrel to process requests
  12. -w, --webrick the default
  13.  
  14. --mode=LEVEL set the running-mode
  15. -b, --benchmark full logging with benchmarks, autoreload 5
  16. -d, --debug the default, full logging, autoreload 5
  17. -t, --stage log infos/errors, autoreload 10
  18. -l, --live log errors, autoreload 20
  19. -s, --silent no logging, autoreload 40
  20.  
  21. -o, --host which host should ramaze listen for requests
  22. default is 0.0.0.0
  23. -p, --port what port should ramaze use
  24. default is 7000
  25.  
  26. -n, --no-errorpage don't use the default errorpage of ramaze
  27. helpful if you want to make sure noone can
  28. ever see your code by accident or for testing
  29. --template-root set a custom template-root for the whole
  30. application, please note that ~ is not
  31. expanded to your home-directory
  32. --autoreload=N set how frequent ramaze should search for
  33. updated files in your application
  34. default depends on the (-mode)
  35. -r, --run-loose don't take control after startup.
  36. this is useful for testcases.
  37. --cache use the simple caching based on the signature
  38. of your requests (experimental)
  39. --tidy run Tool::Tidy over text/html output
  40.  
  41. -h, --help print this help
  42. -v, --version print the version
  43. -c, --copyright print the copyrith
  44.  
  45. Please report bugs to <m.fellinger at gmail.com>
  46. }.strip
  47.  
  48. runner = ARGV.find{|file| File.file?(file)} || 'main.rb'
  49.  
  50. begin
  51. require 'getoptlong'
  52.  
  53. # memo:
  54. # REQUIRED_ARGUMENT, NO_ARGUMENT, OPTIONAL_ARGUMENT
  55.  
  56. opts = GetoptLong.new *[
  57. [ '--adapter', '-a', GetoptLong::REQUIRED_ARGUMENT ],
  58. [ '--mongrel', '-m', GetoptLong::NO_ARGUMENT ],
  59. [ '--webrick', '-w', GetoptLong::NO_ARGUMENT ],
  60.  
  61. [ '--mode', GetoptLong::REQUIRED_ARGUMENT ],
  62. [ '--benchmark', '-b', GetoptLong::NO_ARGUMENT ],
  63. [ '--debug', '-d', GetoptLong::NO_ARGUMENT ],
  64. [ '--stage', '-t', GetoptLong::NO_ARGUMENT ],
  65. [ '--live', '-l', GetoptLong::NO_ARGUMENT ],
  66. [ '--silent', '-s', GetoptLong::NO_ARGUMENT ],
  67.  
  68. [ '--host', '-o', GetoptLong::REQUIRED_ARGUMENT ],
  69. [ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
  70.  
  71. [ '--no-errorpage', '-n', GetoptLong::NO_ARGUMENT ],
  72. [ '--template-root', GetoptLong::REQUIRED_ARGUMENT ],
  73. [ '--autoreload', GetoptLong::REQUIRED_ARGUMENT ],
  74. [ '--run-loose', '-r', GetoptLong::NO_ARGUMENT ],
  75.  
  76. [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
  77. [ '--version', '-v', GetoptLong::NO_ARGUMENT ],
  78. [ '--copyright', '-c', GetoptLong::NO_ARGUMENT ],
  79. ]
  80.  
  81. options = {}
  82.  
  83. opts.each do |opt, arg|
  84. p opt => arg
  85. sopt = opt[2..-1].gsub('-', '_').intern
  86.  
  87. case sopt
  88. when :help
  89. puts usage
  90. exit
  91. when :version
  92. puts "ramaze #{Ramaze::VERSION}"
  93. exit
  94. when :copyright
  95. puts "Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com"
  96. puts "All files in this distribution are subject to the terms of the Ruby license."
  97. exit
  98. when :adapter
  99. options[:adapter] = arg.intern
  100. when :mongrel, :webrick
  101. options[:adapter] = sopt
  102. when :mode
  103. options[:mode] = arg.intern
  104. when :benchmark, :debug, :stage, :live, :silent
  105. options[:mode] = sopt
  106. when :host
  107. options[:host] = arg
  108. when :port
  109. options[:port] = arg
  110. when :no_errorpage
  111. options[:error_page] = false
  112. when :template_root
  113. options[:template_root] = arg
  114. when :autoreload
  115. raise "implement me"
  116. when :run_loose
  117. options[:run_loose] = true
  118. end
  119. end
  120.  
  121. Ramaze.setup_global(options)
  122.  
  123. puts "running #{File.expand_path(runner)}"
  124. require runner
  125.  
  126. Ramaze.start(options)
  127. rescue LoadError => ex
  128. puts ex
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement