Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Aug 16, 2012
0 parents commit 79cc168
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
@@ -0,0 +1,30 @@
# heroku-docs

## Installation

$ heroku plugins:install http://github.com/geemus/heroku-docs.git

## Usage

$ heroku docs dynos
Opening dynos docs... done

$ heroku docs dyno
! No dyno article found.
! Perhaps you meant one of these:
! dynos # Dynos and the Dyno Manifold
! dyno-requests # How many requests can a dyno serve?
! addons_with_dyno_hour_usage # Add-ons with Dyno Hour Usage
! how-much-does-a-dyno-cost # How much does a dyno cost?
! scaling-aspen-bamboo # Scaling Dynos and Workers on Aspen/Bamboo
! background-jobs-queueing # Worker Dynos, Background Jobs and Queueing
! usage-and-billing # Usage & Billing
! prorate-charges # How do you prorate charges?
! oneoff-admin-ps # One-off Processes
! key-concepts-performance # Key Concepts in Performance on Bamboo
! backlog-too-deep # Backlog Too Deep
! ssh-access # SSH Access
! maintenance-mode # Maintenance Mode
! ps # Managing Heroku Processes
! erosion-resistance # Erosion-resistance

50 changes: 50 additions & 0 deletions init.rb
@@ -0,0 +1,50 @@
require "heroku/command"
require "excon"

# access devcenter documentation
class Heroku::Command::Docs < Heroku::Command::Base

# docs TOPIC
#
# get devcenter documentation on TOPIC
#
def index
unless topic = shift_argument
error("Usage: heroku docs: TOPIC\nMust specify TOPIC to open docs for.")
end

docs(topic, "https://devcenter.heroku.com/articles/#{topic}")
end

private

def docs(topic, url)
head = Excon.head(url)
case head.status
when 200
action("Opening #{topic} docs") do
require('launchy')
launchy = Launchy.open(url)
if launchy.respond_to?(:join)
launchy.join
end
end
when 301, 302
docs(head.headers['Location'])
when 404
message = [
"No #{topic} article found."
]
suggestions = json_decode(Excon.get('https://devcenter.heroku.com/articles.json', :query => { :q => topic }).body)['devcenter']
unless suggestions.empty?
message << "Perhaps you meant one of these:"
longest = suggestions.map {|suggestion| suggestion['url'].split('/articles/').last.length }.max
suggestions.each do |suggestion|
message << " %-#{longest}s # %s" % [suggestion['url'].split('/articles/').last, suggestion['title']]
end
end
error(message.join("\n"))
end
end

end

0 comments on commit 79cc168

Please sign in to comment.