Created
May 21, 2016 16:44
-
-
Save frank184/19b0fb3413b9cc865a61b7698060675f to your computer and use it in GitHub Desktop.
Rake Task that controls the Ruby API for localtunnel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/tasks/localtunnel.rake | |
namespace :localtunnel do | |
desc "Starts the LocalTunnel instace" | |
task start: :environment do | |
begin | |
if Rails.env.production? | |
raise "Trying to launch Localtunnel in production".red | |
end | |
default_subdomain = "whatever" | |
default_port = 3000 | |
print "Enter an subdomain or blank (default: #{default_subdomain}) " | |
subdomain = $stdin.gets.chomp.downcase | |
subdomain = default_subdomain if subdomain.blank? | |
print "Enter an port or blank (default: #{default_port}) " | |
port = $stdin.gets.chomp.downcase | |
port = default_port if port.blank? | |
unless Localtunnel::Client.running? | |
puts "=> Started localtunnel at #{Localtunnel::Client.start(port: port, subdomain: subdomain)}" | |
else | |
puts "=> Localtunnel already running..." | |
end | |
rescue => e | |
puts e.message.red | |
end | |
end | |
desc "Stops the LocalTunnel instance" | |
task stop: :environment do | |
if Localtunnel::Client.running? | |
puts "=> Stopping Localtunnel at #{Localtunnel::Client.url}" | |
Localtunnel::Client.stop | |
else | |
puts "=> Localtunnel was not running..." | |
end | |
end | |
desc "Stops, then Stars the LocalTunnel instance" | |
task restart: [:start, :stop] | |
desc "Returns the URL that LocalTunnel is using" | |
task url: :environment do | |
puts "=> Running localtunnel at #{Localtunnel::Client.url}" | |
end | |
desc "Returns whether or not LocalTunnel is running successfully" | |
task running: :environment do | |
Localtunnel::Client.running? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment