Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search resources by URL #4

Merged
merged 4 commits into from
Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 37 additions & 31 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,52 @@ mode = Config::Mode::Replay
base_url : String? = nil
query_options : Array(String) = [] of String

parsed = OptionParser.parse do |parser|
parser.banner = "Replay: Record and Preplay!"
begin
parsed = OptionParser.parse do |parser|
parser.banner = "Replay: Record and Preplay!"

parser.on "-v", "--version", "Show version" do
puts Replay::VERSION
exit
end
parser.on "-v", "--version", "Show version" do
puts Replay::VERSION
exit
end

parser.on "-h", "--help", "Show help" do
puts parser
exit
end
parser.on "-h", "--help", "Show help" do
puts parser
exit
end

parser.on "-p PORT", "--port PORT", "Server port" do |port|
port.to_i16?.try do |port_number|
server_port = port_number
parser.on "-p PORT", "--port PORT", "Server port" do |port|
port.to_i16?.try do |port_number|
server_port = port_number
end
end
end

parser.on "-r URL", "--record URL", "Run as recording mode" do |url|
mode = Config::Mode::Record
base_url = url
end
parser.on "-r URL", "--record URL", "Run as recording mode" do |url|
mode = Config::Mode::Record
base_url = url
end

parser.on "-R URL", "--replay URL", "Run as replaying mode" do |url|
mode = Config::Mode::Replay
base_url = url
end
parser.on "-R URL", "--replay URL", "Run as replaying mode" do |url|
mode = Config::Mode::Replay
base_url = url
end

parser.on "-f URL", "--find URL", "Find resources" do |_|
query_options = ARGV[1..]
base_url = query_options[0]
mode = Config::Mode::Replay
end
parser.on "-f URL", "--find URL", "Find resources" do |_|
query_options = ARGV[1..]
base_url = query_options[0]
mode = Config::Mode::Replay
end

parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
end
end
rescue ex
puts ex
STDERR.puts parsed
exit(1)
end

if !base_url
Expand Down