lib/toycol/command.rb in toycol-0.3.0 vs lib/toycol/command.rb in toycol-0.3.1
- old
+ new
@@ -1,11 +1,7 @@
# frozen_string_literal: true
-require "optparse"
-require_relative "./client"
-require_relative "./template_generator"
-
module Toycol
class Command
class Options
@options = {}
@@ -79,29 +75,35 @@
]
end
def client_option_parser
OptionParser.new do |opt|
- opt.on("-p PORT_NUMBER", "--port PORT_NUMBER", "listen on PORT (default: 9292)") do |port|
- ::Toycol::Client.port = port
+ opt.banner = "Usage: #{opt.program_name} client [-h|--help] REQUEST_MESSAGE [arg...]"
+ opt.on("-o HOST", "--host HOST", "connect to HOST (default: localhost)") do |host|
+ Client.host = host
end
+ opt.on("-p PORT_NUMBER", "--port PORT_NUMBER", "connect to PORT (default: 9292)") do |port|
+ Client.port = port
+ end
+
opt.on_head("-h", "--help", "Show this message") { help_command(opt) }
end
end
def server_option_parser
OptionParser.new do |opt|
+ opt.banner = "Usage: #{opt.program_name} server [-h|--help] APPLICATION_PATH [arg...]"
opt.on("-o HOST", "--host HOST", "bind to HOST (default: localhost)") do |host|
::Rack::Handler::Toycol.host = host
end
opt.on("-p PORT_NUMBER", "--port PORT_NUMBER", "listen on PORT (default: 9292)") do |port|
::Rack::Handler::Toycol.port = port
end
- opt.on("-u SERVER_NAME", "--use SERVER_NAME", "switch using SERVER(puma/build_in)") do |server_name|
+ opt.on("-u SERVER_NAME", "--use SERVER_NAME", "switch using SERVER(puma/builtin)") do |server_name|
::Rack::Handler::Toycol.preferred_background_server = server_name
end
opt.on_head("-h", "--help", "Show this message") { help_command(opt) }
end
@@ -136,16 +138,16 @@
options = Options.parse!(@argv)
command = options.delete(:command)
case command
when "client", "c"
- ::Toycol::Client.execute!(options[:request_message])
+ Client.execute!(options[:request_message])
when "server", "s"
ARGV.push("-q", "-s", "toycol")
Rack::Server.start
when "generate", "g"
type = options[:template_type] || "all"
- ::Toycol::TemplateGenerator.generate!(type: type, name: options[:protocol_name])
+ TemplateGenerator.generate!(type: type, name: options[:protocol_name])
end
end
end
end