class Mitt::CLI
Public Class Methods
new(arguments)
click to toggle source
# File lib/mitt/cli.rb, line 7 def initialize(arguments) @arguments = arguments end
Public Instance Methods
run()
click to toggle source
# File lib/mitt/cli.rb, line 11 def run if help_command? print_usage return end port, body = read_args app = Mitt::App.new(body) # Suppress thin's normal startup message Thin::Logging.silent = true puts "Mitt is listening on port #{port}" Rack::Handler::Thin.run app, Port: port rescue InvalidArguments print_usage end
Private Instance Methods
help_command?()
click to toggle source
# File lib/mitt/cli.rb, line 33 def help_command? @arguments.any? { |arg| arg =~ /-+help/ } end
print_usage()
click to toggle source
# File lib/mitt/cli.rb, line 46 def print_usage puts <<USAGE Usage: mitt [port] [body] port: The port to listen on. You may need to run mitt with sudo to listen on a port reserved by your system. Defaults to 8080. body: The http response body used for all requests. Defaults to 'ok'. USAGE end
read_args()
click to toggle source
# File lib/mitt/cli.rb, line 37 def read_args port = (@arguments[0] || 8080).to_i raise InvalidArguments unless port > 0 body = @arguments[1] || 'ok' [port, body] end