diff --git a/bin/memprof b/bin/memprof index dc8dc27..55b7cef 100755 --- a/bin/memprof +++ b/bin/memprof @@ -5,11 +5,8 @@ require 'optparse' require 'restclient' require 'term/ansicolor' -MEMPROF_URL = "https://memprof.com/upload" - MEMPROF_BANNER = <<-EOF Memprof Uploader -http://www.memprof.com ====================== EOF @@ -25,6 +22,7 @@ class MemprofUploader opts.on("-p", "--pid ", Integer, "PID of the process to dump (required)") {|arg| @pid = arg } opts.on("-n", "--name ", "Name for your dump (required)") {|arg| @name = arg } opts.on("-k", "--key ", "Memprof.com API key (required)") {|arg| @key = arg } + opts.on("-u", "--url ", "Memprof.com application URL (default https://memprof.com)") {|arg| @url = arg } opts.on("-d", "--[no-]delete", "Delete dump file after uploading (default true)") {|arg| @delete_dump = arg } opts.on("-s", "--seconds ", Integer, "Seconds to wait for the dump (default 300)") {|arg| @secs = arg } @@ -61,10 +59,19 @@ class MemprofUploader end end + # Make this default to https://memprof.com if the user didn't pass custom application URL. + @url ||= "https://memprof.com" + + unless @url =~ /^https?:\/\/(([a-z0-9\-]+\.)+[a-z]{2,4}|(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))(:\d+)?(\/.*)?$/i + fail_with("#{@url} does not look like a correct URL") + end + + @upload_url = "#{@url}/upload" + # Make this default to true if the user didn't pass any preference. @delete_dump = true if @delete_dump.nil? - # Make this default to 60 if the user didn't pass the number of seconds. + # Make this default to 300 if the user didn't pass the number of seconds. @secs ||= 300 if @file @@ -142,8 +149,8 @@ class MemprofUploader file = File.open(filename, "r") - puts "\nUploading to memprof.com..." - response = RestClient.post(MEMPROF_URL, :upload => file, :name => name, :key => key) + puts "\nUploading to #{@url}..." + response = RestClient.post(@upload_url, :upload => file, :name => name, :key => key) puts "Response from server:" p response.to_s @@ -173,4 +180,4 @@ class MemprofUploader end -MemprofUploader.new(ARGV).run! \ No newline at end of file +MemprofUploader.new(ARGV).run!