From aef16d85c6dde677023888dcc033b2007ea6fab2 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Fri, 5 Mar 2010 16:23:00 -0600 Subject: [PATCH] Use cat for pager by default. --- lib/hub/commands.rb | 7 +++++-- lib/hub/runner.rb | 2 +- test/hub_test.rb | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/hub/commands.rb b/lib/hub/commands.rb index 18c5a0b6..87de2e62 100644 --- a/lib/hub/commands.rb +++ b/lib/hub/commands.rb @@ -290,10 +290,13 @@ module Hub # $ hub help # (print improved help text) def help(args) - if args[1] == 'hub' + command = args.grep(/^[^-]/)[1] + + if command == 'hub' puts hub_manpage exit - elsif args.size == 1 + elsif command.nil? + ENV['GIT_PAGER'] = '' if args.grep(/^-{1,2}p/).empty? # Use `cat`. puts improved_help_text exit end diff --git a/lib/hub/runner.rb b/lib/hub/runner.rb index 17cc2353..477a04a8 100644 --- a/lib/hub/runner.rb +++ b/lib/hub/runner.rb @@ -11,7 +11,7 @@ module Hub @args = Args.new(args) # Hack to emulate git-style - @args[0] = 'help' if @args.empty? + @args.unshift 'help' if @args.grep(/^[^-]|version/).empty? if Commands.respond_to?(@args[0]) Commands.send(@args[0], @args) diff --git a/test/hub_test.rb b/test/hub_test.rb index c4a79314..2029c506 100644 --- a/test/hub_test.rb +++ b/test/hub_test.rb @@ -169,7 +169,7 @@ class HubTest < Test::Unit::TestCase def test_version out = hub('--version') - assert_includes "git version 1.6", out + assert_includes "git version", out assert_includes "hub version #{Hub::Version}", out end @@ -181,6 +181,10 @@ class HubTest < Test::Unit::TestCase assert_equal Hub::Commands.improved_help_text, hub("") end + def test_help_with_pager + assert_equal Hub::Commands.improved_help_text, hub("-p") + end + def test_help_hub help_manpage = hub("help hub") assert_includes "git + hub = github", help_manpage -- GitLab