class Heroku::JSPlugin
Public Class Methods
arch()
click to toggle source
# File lib/heroku/jsplugin.rb, line 144 def self.arch case RbConfig::CONFIG['host_cpu'] when /x86_64/ "amd64" when /arm/ "arm" else "386" end end
bin()
click to toggle source
# File lib/heroku/jsplugin.rb, line 105 def self.bin if os == 'windows' File.join(Heroku::Helpers.home_directory, ".heroku", "heroku-cli.exe") else File.join(Heroku::Helpers.home_directory, ".heroku", "heroku-cli") end end
commands()
click to toggle source
# File lib/heroku/jsplugin.rb, line 73 def self.commands commands_info['commands'] rescue $stderr.puts "error loading plugin commands" # Remove v4 if it is causing issues (for now) File.delete(bin) rescue nil return [] end
commands_info()
click to toggle source
# File lib/heroku/jsplugin.rb, line 82 def self.commands_info copy_ca_cert rescue nil # TODO: remove this once most of the users have the cacert setup @commands_info ||= json_decode(%x`"#{bin}" commands --json`) end
copy_ca_cert()
click to toggle source
# File lib/heroku/jsplugin.rb, line 131 def self.copy_ca_cert to = File.join(Heroku::Helpers.home_directory, ".heroku", "cacert.pem") return if File.exists?(to) from = File.expand_path("../../../data/cacert.pem", __FILE__) FileUtils.copy(from, to) end
excon_opts()
click to toggle source
# File lib/heroku/jsplugin.rb, line 176 def self.excon_opts if os == 'windows' || ENV['HEROKU_SSL_VERIFY'] == 'disable' # S3 SSL downloads do not work from ruby in Windows {:ssl_verify_peer => false} else {} end end
install(name, opts={})
click to toggle source
# File lib/heroku/jsplugin.rb, line 87 def self.install(name, opts={}) self.setup system "\"#{bin}\" plugins:install #{name}" if opts[:force] || !self.is_plugin_installed?(name) error "error installing plugin #{name}" if $? != 0 end
is_plugin_installed?(name)
click to toggle source
# File lib/heroku/jsplugin.rb, line 62 def self.is_plugin_installed?(name) plugins.any? { |p| p[:name] == name } end
load!()
click to toggle source
# File lib/heroku/jsplugin.rb, line 21 def self.load! return unless setup? this = self topics.each do |topic| Heroku::Command.register_namespace( :name => topic['name'], :description => " #{topic['description']}" ) unless topic['hidden'] || Heroku::Command.namespaces.include?(topic['name']) end commands.each do |plugin| help = "\n\n #{plugin['fullHelp'].split("\n").join("\n ")}" klass = Class.new do def initialize(args, opts) @args = args @opts = opts end end klass.send(:define_method, :run) do this.run(plugin['topic'], plugin['command'], ARGV[1..-1]) end Heroku::Command.register_command( :command => plugin['command'] ? "#{plugin['topic']}:#{plugin['command']}" : plugin['topic'], :namespace => plugin['topic'], :klass => klass, :method => :run, :banner => plugin['usage'], :summary => " #{plugin['description']}", :help => help, :hidden => plugin['hidden'], ) end end
manifest()
click to toggle source
# File lib/heroku/jsplugin.rb, line 172 def self.manifest @manifest ||= JSON.parse(Excon.get("https://d1gvo455cekpjp.cloudfront.net/master/manifest.json", excon_opts).body) end
new(args, opts)
click to toggle source
# File lib/heroku/jsplugin.rb, line 33 def initialize(args, opts) @args = args @opts = opts end
os()
click to toggle source
# File lib/heroku/jsplugin.rb, line 155 def self.os case RbConfig::CONFIG['host_os'] when /darwin|mac os/ "darwin" when /linux/ "linux" when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ "windows" when /openbsd/ "openbsd" when /freebsd/ "freebsd" else raise "unsupported on #{RbConfig::CONFIG['host_os']}" end end
plugins()
click to toggle source
# File lib/heroku/jsplugin.rb, line 54 def self.plugins return [] unless setup? @plugins ||= %x`"#{bin}" plugins`.lines.map do |line| name, version = line.split { :name => name, :version => version } end end
run(topic, command, args)
click to toggle source
# File lib/heroku/jsplugin.rb, line 138 def self.run(topic, command, args) cmd = command ? "#{topic}:#{command}" : topic debug("running #{cmd} on v4") exec self.bin, cmd, *args end
setup()
click to toggle source
# File lib/heroku/jsplugin.rb, line 113 def self.setup return if File.exist? bin $stderr.print "Installing Heroku Toolbelt v4..." FileUtils.mkdir_p File.dirname(bin) copy_ca_cert opts = excon_opts.merge(:middlewares => Excon.defaults[:middlewares] + [Excon::Middleware::Decompress]) resp = Excon.get(url, opts) open(bin, "wb") do |file| file.write(resp.body) end File.chmod(0755, bin) if Digest::SHA1.file(bin).hexdigest != manifest['builds'][os][arch]['sha1'] File.delete bin raise 'SHA mismatch for heroku-cli' end $stderr.puts " done" end
setup?()
click to toggle source
# File lib/heroku/jsplugin.rb, line 6 def self.setup? File.exists? bin end
topics()
click to toggle source
# File lib/heroku/jsplugin.rb, line 66 def self.topics commands_info['topics'] rescue $stderr.puts "error loading plugin topics" return [] end
try_takeover(command, args)
click to toggle source
# File lib/heroku/jsplugin.rb, line 10 def self.try_takeover(command, args) topic, cmd = command.split(':', 2) if cmd command = commands.find { |t| t["topic"] == topic && t["command"] == cmd } else command = commands.find { |t| t["topic"] == topic && (t["command"] == nil || t["default"]) } end return if !command || command["hidden"] run(command['topic'], command['command'], ARGV[1..-1]) end
uninstall(name)
click to toggle source
# File lib/heroku/jsplugin.rb, line 93 def self.uninstall(name) system "\"#{bin}\" plugins:uninstall #{name}" end
update()
click to toggle source
# File lib/heroku/jsplugin.rb, line 97 def self.update system "\"#{bin}\" update" end
url()
click to toggle source
# File lib/heroku/jsplugin.rb, line 185 def self.url manifest['builds'][os][arch]['url'] + ".gz" end
version()
click to toggle source
# File lib/heroku/jsplugin.rb, line 101 def self.version %x`"#{bin}" version` end