Sha256: 92803b749ce905c5a0cde3e0a2d4cdd8531cbcc94dcabe7ebd56e717b5a8e46b
Contents?: true
Size: 1.47 KB
Versions: 13
Compression:
Stored size: 1.47 KB
Contents
require 'excon' require 'launchy' require 'json' require 'yaml' module Devcenter::Commands class Base include Devcenter::Logger include Devcenter::Helpers def self.run(*args) if Devcenter::GemVersionChecker.new_version_available? say "devcenter has a new version available, please update with: gem install devcenter" return unless agree('Continue executing your command? (yes/no)') end command = self.new(*args) end def initialize(*args) @validation_errors = [] validate if @validation_errors.any? @validation_errors.each{ |e| say e } else run end end def validate; end # add error messages to @validation_errors def run; end protected def article_not_found!(slug) message = ["No #{slug} article found."] suggestions = JSON.parse(Devcenter::Client.get(:path => search_api_path, :query => { :q => slug, :source => 'devcenter-cli' }).body)['devcenter'] suggestions.select!{ |s| article_url?(s['full_url']) } suggestions.each{ |s| s['slug'] = slug_from_article_url(s['full_url']) } unless suggestions.empty? message << "Perhaps you meant one of these:" longest = suggestions.map {|suggestion| suggestion['slug'].size }.max suggestions.each do |suggestion| message << " %-#{longest}s # %s" % [suggestion['slug'], suggestion['title']] end end say message.join("\n") exit end end end
Version data entries
13 entries across 13 versions & 1 rubygems