Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
require v4
Browse files Browse the repository at this point in the history
  • Loading branch information
dickeyxxx committed Aug 26, 2015
1 parent b6411b0 commit ff0c6d0
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion lib/heroku/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def self.start(*args)
$stdout.sync = true if $stdout.isatty
Heroku::Updater.warn_if_updating
command = args.shift.strip rescue "help"
Heroku::JSPlugin.try_takeover(command, args) if Heroku::JSPlugin.setup?
Heroku::JSPlugin.setup
Heroku::JSPlugin.try_takeover(command, args)
require 'heroku/command'
Heroku::Git.check_git_version
Heroku::Command.load
Expand Down
2 changes: 1 addition & 1 deletion lib/heroku/command/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def uninstall
action("Uninstalling #{plugin.name}") do
plugin.uninstall
end
elsif Heroku::JSPlugin.setup?
else
Heroku::JSPlugin.uninstall(plugin.name)
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/heroku/command/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class Heroku::Command::Update < Heroku::Command::Base
def index
validate_arguments!
update_from_url(false)
if Heroku::JSPlugin.setup?
Heroku::JSPlugin.update
end
Heroku::JSPlugin.update
end

# update:beta
Expand Down
2 changes: 1 addition & 1 deletion lib/heroku/command/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
validate_arguments!

display(Heroku.user_agent)
display(Heroku::JSPlugin.version) if Heroku::JSPlugin.setup?
display(Heroku::JSPlugin.version)

Heroku::Command::Plugins.new.index
end
Expand Down
11 changes: 2 additions & 9 deletions lib/heroku/jsplugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
class Heroku::JSPlugin
extend Heroku::Helpers

def self.setup?
File.exists? bin
end

def self.try_takeover(command, args)
topic, cmd = command.split(':', 2)
if cmd
Expand All @@ -19,7 +15,6 @@ def self.try_takeover(command, args)
end

def self.load!
return unless setup?
this = self
topics.each do |topic|
Heroku::Command.register_namespace(
Expand Down Expand Up @@ -52,7 +47,6 @@ def initialize(args, opts)
end

def self.plugins
return [] unless setup?
@plugins ||= `"#{bin}" plugins`.lines.map do |line|
name, version = line.split
{ :name => name, :version => version }
Expand Down Expand Up @@ -80,12 +74,10 @@ def self.commands
end

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(`"#{bin}" commands --json`)
end

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
Expand All @@ -112,6 +104,7 @@ def self.bin

def self.setup
return if File.exist? bin
require 'excon'
$stderr.print "Installing Heroku Toolbelt v4..."
FileUtils.mkdir_p File.dirname(bin)
copy_ca_cert
Expand All @@ -125,7 +118,7 @@ def self.setup
File.delete bin
raise 'SHA mismatch for heroku-cli'
end
$stderr.puts " done"
$stderr.puts " done.\nFor more information on Toolbelt v4: https://github.com/heroku/heroku-cli"
end

def self.copy_ca_cert
Expand Down
1 change: 0 additions & 1 deletion spec/heroku/command/keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module Heroku::Command
it "adds a key from a specified keyfile path" do
# This is because the JSPlugin makes a call to File.exists
# Not pretty, but will always work and should be temporary
allow(Heroku::JSPlugin).to receive(:setup?).and_return(false)
expect(File).to receive(:exists?).with('.git').and_return(false)
expect(File).to receive(:exists?).with('/my/key.pub').and_return(true)
expect(File).to receive(:read).with('/my/key.pub').and_return(KEY)
Expand Down
1 change: 1 addition & 0 deletions spec/heroku/command/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Heroku::Command
expect(stderr).to eq("")
expect(stdout).to eq <<-STDOUT
#{Heroku.user_agent}
heroku-cli/4.0.0-4f2c5c5 (amd64-darwin) go1.5
You have no installed plugins.
STDOUT
end
Expand Down
1 change: 1 addition & 0 deletions spec/heroku/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Heroku::Command::Test::Multiple; end
it "displays the version if --version is used" do
expect(heroku("--version")).to eq <<-STDOUT
#{Heroku.user_agent}
heroku-cli/4.0.0-4f2c5c5 (amd64-darwin) go1.5
You have no installed plugins.
STDOUT
end
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ module Heroku::Rollbar
def self.error(e); end
end

require "heroku/jsplugin"
class Heroku::JSPlugin
def self.topics; [] end
def self.commands; [] end
def self.setup; end
def self.run; end
def self.plugins; [] end
def self.version; 'heroku-cli/4.0.0-4f2c5c5 (amd64-darwin) go1.5' end
end

require "support/display_message_matcher"
require "support/organizations_mock_helper"
require "support/addons_helper"
Expand Down

0 comments on commit ff0c6d0

Please sign in to comment.