Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from jessmartin/master

Changes to support the new heroku help system
  • Loading branch information...
commit f252bd131ef4e9f72f7db1736d144da006ca67cc 2 parents e84a3cf + 1fb7769
Shay Frendt authored
Showing with 124 additions and 67 deletions.
  1. +124 −67 init.rb
191 init.rb
View
@@ -6,18 +6,6 @@
module Heroku::Command
class Ranger < BaseWithApp
- Help.group("Ranger") do |group|
- group.command "ranger", "show current app status"
- group.command "ranger:domains", "list domains being monitored"
- group.command "ranger:domains add <url>", "start monitoring a domain"
- group.command "ranger:domains remove <url>", "stop monitoring a domain"
- group.command "ranger:domains clear", "stop monitoring all domains"
- group.command "ranger:watchers", "list current app watchers"
- group.command "ranger:watchers add <email>", "add an app watcher"
- group.command "ranger:watchers remove <email>", "remove an app watcher"
- group.command "ranger:watchers clear", "remove all app watchers"
- end
-
def initialize(*args)
super
@config_vars = heroku.config_vars(app)
@@ -26,12 +14,11 @@ def initialize(*args)
@app_owner = heroku.info(app)[:owner]
abort(" ! Please add the ranger addon first.") unless @ranger_api_key
end
-
- def authenticated_resource(path)
- host = "https://rangerapp.com/api/v1"
- RestClient::Resource.new("#{host}#{path}")
- end
+ # ranger
+ #
+ # show current app status
+ #
def index
if get_status
dependencies = @current_status
@@ -51,6 +38,125 @@ def index
end
end
+ # ranger:domains
+ #
+ # list domains being monitored
+ #
+ def domains
+ if args.empty?
+ domain_list
+ return
+ end
+
+ case args.shift
+ when "add"
+ url = args.shift
+ create_dependency(url)
+ puts "Added #{url} to the monitoring list"
+ return
+ when "remove"
+ url = args.shift
+ remove_url(url)
+ return
+ when "clear"
+ clear_all_dependencies
+ puts "All domains removed from the monitoring list"
+ return
+ end
+ raise(CommandFailed, "see: heroku help ranger")
+ end
+
+ # ranger:add_domain DOMAIN
+ #
+ # start monitoring a domain
+ #
+ def add_domain
+ url = args.shift
+ create_dependency(url)
+ puts "Added #{url} to the monitoring list"
+ end
+
+ # ranger:remove_domain DOMAIN
+ #
+ # stop monitoring a domain
+ #
+ def remove_domain
+ url = args.shift
+ remove_url(url)
+ end
+
+ # ranger:clear_domains
+ #
+ # stop monitoring all domains
+ #
+ def clear_domains
+ clear_all_dependencies
+ puts "All domains removed from the monitoring list"
+ end
+
+ # ranger:watchers
+ #
+ # list current app watchers
+ #
+ def watchers
+ if args.empty?
+ watchers_list
+ return
+ end
+
+ case args.shift
+ when "add"
+ email = args.shift
+ create_watcher(email)
+ puts "Added #{email} as a watcher"
+ return
+ when "remove"
+ email = args.shift
+ remove_watcher(email)
+ return
+ when "clear"
+ clear_all_watchers
+ puts "All watchers removed"
+ return
+ end
+ raise(CommandFailed, "see: heroku help ranger")
+ end
+
+ # ranger:add_watcher EMAIL
+ #
+ # add a watcher
+ #
+ def add_watcher
+ email = args.shift
+ create_watcher(email)
+ puts "Added #{email} as a watcher"
+ end
+
+ # ranger:remove_watcher EMAIL
+ #
+ # remove a watcher
+ #
+ def remove_watcher
+ email = args.shift
+ remove_watcher(email)
+ end
+
+ # ranger:clear_watchers
+ #
+ # remove all watchers
+ #
+ def clear_watchers
+ clear_all_watchers
+ puts "All watchers removed"
+ end
+
+ protected
+
+ def authenticated_resource(path)
+ host = "https://rangerapp.com/api/v1"
+ RestClient::Resource.new("#{host}#{path}")
+ end
+
def up_or_down(code)
case code
when 200
@@ -137,7 +243,7 @@ def no_domains_monitored
puts "No domains are being monitored for this app."
puts "-----------------------------------------------"
puts "\nMonitor a domain like this:"
- puts "\n heroku ranger:domains add http://yourapp.heroku.com\n\n"
+ puts "\n heroku ranger:add_domain http://yourapp.heroku.com\n\n"
end
def domain_list
@@ -213,54 +319,5 @@ def delete_watcher(id)
false
end
end
-
- def domains
- if args.empty?
- domain_list
- return
- end
-
- case args.shift
- when "add"
- url = args.shift
- create_dependency(url)
- puts "Added #{url} to the monitoring list"
- return
- when "remove"
- url = args.shift
- remove_url(url)
- return
- when "clear"
- clear_all_dependencies
- puts "All domains removed from the monitoring list"
- return
- end
- raise(CommandFailed, "usage: heroku ranger:domains <add | remove | clear>")
- end
-
- def watchers
- if args.empty?
- watchers_list
- return
- end
-
- case args.shift
- when "add"
- email = args.shift
- create_watcher(email)
- puts "Added #{email} as a watcher"
- return
- when "remove"
- email = args.shift
- remove_watcher(email)
- return
- when "clear"
- clear_all_watchers
- puts "All watchers removed"
- return
- end
- raise(CommandFailed, "usage: heroku ranger:watchers <add | remove | clear>")
- end
-
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.