From 79cc1686f919b00ffd0336fe79c2646afde86456 Mon Sep 17 00:00:00 2001 From: geemus Date: Thu, 16 Aug 2012 17:22:00 -0500 Subject: [PATCH] initial setup --- README.md | 30 ++++++++++++++++++++++++++++++ init.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 README.md create mode 100644 init.rb diff --git a/README.md b/README.md new file mode 100644 index 0000000..a165eb9 --- /dev/null +++ b/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 + diff --git a/init.rb b/init.rb new file mode 100644 index 0000000..2586edb --- /dev/null +++ b/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