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

Commit

Permalink
Fix help and plugins (#2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo authored and jdx committed Mar 21, 2017
1 parent 02caa97 commit 522c550
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
3.99.1 2017-3-17
====================
Fix help and listing plugins

3.99.0 2017-03-13
=================
Add deprecation message
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
heroku (3.99.0)
heroku (3.99.1)
heroku-api (= 0.4.2)
launchy (= 2.4.3)
multi_json (= 1.11.2)
Expand Down
2 changes: 1 addition & 1 deletion lib/heroku/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.start(*args)
command = args.shift.strip rescue "help"
Heroku::Analytics.skip_analytics # just sets the config for the analytics
Heroku::JSPlugin.setup
Heroku::JSPlugin.try_takeover(command, args)
Heroku::JSPlugin.try_takeover(command)
require 'heroku/command'
Heroku::Git.check_git_version
Heroku::Command.load
Expand Down
5 changes: 3 additions & 2 deletions lib/heroku/command/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def index
styled_header("Installed Plugins")
styled_array(plugins)
end
::Heroku::JSPlugin.list
end

# plugins:install NAME
Expand Down Expand Up @@ -149,7 +150,7 @@ def commands
type_and_percentage = counts.keys.sort.map{|type| {:type => type, :count => counts[type]}}

if options[:csv]
csv_str = CSV.generate do |csv|
csv_str = CSV.generate do |csv|
csv << header
sorted_cmd.each {|cmd| csv << attrs.map{|attr| cmd[attr]}}

Expand All @@ -174,7 +175,7 @@ def command_to_hash(type, cmd, command)
end

def command_list_to_hash(commands, type)
commands.inject({}) do |h, command|
commands.inject({}) do |h, command|
cmd = command['command'] ? "#{command['topic']}:#{command['command']}" : command['topic']
h[cmd] = command_to_hash(type, cmd, command)
if command['default']
Expand Down
8 changes: 6 additions & 2 deletions lib/heroku/jsplugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
class Heroku::JSPlugin
extend Heroku::Helpers

def self.try_takeover(command, args)
def self.list
system "\"#{bin}\" plugins"
end

def self.try_takeover(command)
return if ALWAYS_RUBY_COMMANDS.include?(command)
run(ARGV[0], nil, ARGV[1..-1])
run((ARGV[0] || "help"), nil, ARGV[1..-1])
end

def self.install(name, opts={})
Expand Down
2 changes: 1 addition & 1 deletion lib/heroku/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Heroku
VERSION = "3.99.0"
VERSION = "3.99.1"
end
64 changes: 64 additions & 0 deletions spec/heroku/jsplugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,69 @@ module Heroku
allow(ENV).to receive(:[]).and_call_original
end
end

context '.try_takeover' do
context 'global help' do
it 'displays via $ heroku' do
cmd = ['help'] # 'help' via cli.js:26
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('help', nil, [])
Heroku::JSPlugin.try_takeover(cmd[0])
end

it 'displays via $ heroku help' do
cmd = ['help']
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('help', nil, [])
Heroku::JSPlugin.try_takeover(cmd[0])
end

it 'displays via $ heroku --help' do
cmd = ['--help']
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('--help', nil, [])
Heroku::JSPlugin.try_takeover(cmd[0])
end
end

context 'topic help' do
it 'displays via $ heroku help plugins' do
cmd = ['help', 'plugins']
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('help', nil, ['plugins'])
Heroku::JSPlugin.try_takeover(cmd[0])
end

it 'displays via $ heroku --help plugins' do
cmd = ['--help', 'plugins']
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('--help', nil, ['plugins'])
Heroku::JSPlugin.try_takeover(cmd[0])
end
end

context 'help help' do
it 'displays via $ heroku help help' do
cmd = ['help', 'help']
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('help', nil, ['help'])
Heroku::JSPlugin.try_takeover(cmd[0])
end

it 'displays via $ heroku --help help' do
cmd = ['--help', 'help']
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('--help', nil, ['help'])
Heroku::JSPlugin.try_takeover(cmd[0])
end

it 'displays via $ heroku help --help' do
cmd = ['help', '--help']
stub_argv(cmd)
expect(Heroku::JSPlugin).to receive(:run).with('help', nil, ['--help'])
Heroku::JSPlugin.try_takeover(cmd[0])
end
end
end
end
end
7 changes: 5 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

if (Heroku::Helpers.running_on_windows?)
$stdin = File.new("nul")
else
else
$stdin = File.new("/dev/null")
end

Expand Down Expand Up @@ -255,7 +255,7 @@ class Heroku::JSPlugin
def self.topics; [] end
def self.commands; [] end
def self.setup; end
def self.run; end
def self.run (t=nil, c=nil, a=nil); end
def self.plugins; [] end
def self.version; 'heroku-cli/4.0.0-4f2c5c5 (amd64-darwin) go1.5' end
end
Expand All @@ -271,3 +271,6 @@ def self.version; 'heroku-cli/4.0.0-4f2c5c5 (amd64-darwin) go1.5' end
config.after { RR.reset }
end

def stub_argv cmd
allow(ARGV).to receive(:[]) { |i| cmd[i] }
end

0 comments on commit 522c550

Please sign in to comment.