mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Don't show tasks with blank descriptions, or with the [internal] tag in their descriptions, in the task list unless verbose listing is requested.
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6414 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
7748dedecd
commit
0e5600f1c9
4 changed files with 52 additions and 6 deletions
|
@ -26,6 +26,11 @@ module Capistrano
|
|||
if tasks.empty?
|
||||
warn "There are no tasks available. Please specify a recipe file to load."
|
||||
else
|
||||
all_tasks_length = tasks.length
|
||||
if options[:verbose].to_i < 1
|
||||
tasks = tasks.reject { |t| t.description.empty? || t.description =~ /^\[internal\]/ }
|
||||
end
|
||||
|
||||
tasks = tasks.sort_by { |task| task.fully_qualified_name }
|
||||
|
||||
longest = tasks.map { |task| task.fully_qualified_name.length }.max
|
||||
|
@ -36,8 +41,15 @@ module Capistrano
|
|||
puts "cap %-#{longest}s # %s" % [task.fully_qualified_name, task.brief_description(max_length)]
|
||||
end
|
||||
|
||||
if all_tasks_length > tasks.length
|
||||
puts
|
||||
puts "Some tasks were not listed, either because they have no description,"
|
||||
puts "or because they are only used internally by other tasks. To see all"
|
||||
puts "tasks, type `#{$0} -Tv'."
|
||||
end
|
||||
|
||||
puts
|
||||
puts "Extended help may be available for any of these tasks."
|
||||
puts "Extended help may be available for these tasks."
|
||||
puts "Type `#{$0} -e taskname' to view it."
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,7 +64,10 @@ module Capistrano
|
|||
|
||||
opts.on("-T", "--tasks",
|
||||
"List all tasks in the loaded recipe files."
|
||||
) { |value| options[:tasks] = true }
|
||||
) do
|
||||
options[:tasks] = true
|
||||
options[:verbose] ||= 0
|
||||
end
|
||||
|
||||
opts.on("-V", "--version",
|
||||
"Display the Capistrano version, and exit."
|
||||
|
|
|
@ -19,6 +19,7 @@ class CLIHelpTest < Test::Unit::TestCase
|
|||
|
||||
def setup
|
||||
@cli = MockCLI.new
|
||||
@cli.options[:verbose] = 0
|
||||
@ui = stub("ui", :output_cols => 80)
|
||||
MockCLI.stubs(:ui).returns(@ui)
|
||||
end
|
||||
|
@ -72,6 +73,35 @@ class CLIHelpTest < Test::Unit::TestCase
|
|||
@cli.task_list(config)
|
||||
end
|
||||
|
||||
def test_task_list_should_not_include_tasks_with_blank_description_or_internal_by_default
|
||||
t1 = task("c")
|
||||
t1.expects(:brief_description).returns("hello")
|
||||
t2 = task("d", "d", "[internal] howdy")
|
||||
t2.expects(:brief_description).never
|
||||
t3 = task("e", "e", "")
|
||||
t3.expects(:brief_description).never
|
||||
|
||||
config = mock("config", :task_list => [t1, t2, t3])
|
||||
@cli.stubs(:puts)
|
||||
@cli.expects(:puts).never.with { |s,| (s || "").include?("[internal]") || s =~ /#\s*$/ }
|
||||
@cli.task_list(config)
|
||||
end
|
||||
|
||||
def test_task_list_should_include_tasks_with_blank_descriptions_and_internal_when_verbose
|
||||
t1 = task("c")
|
||||
t1.expects(:brief_description).returns("hello")
|
||||
t2 = task("d", "d", "[internal] howdy")
|
||||
t2.expects(:brief_description).returns("[internal] howdy")
|
||||
t3 = task("e", "e", "")
|
||||
t3.expects(:brief_description).returns("")
|
||||
|
||||
config = mock("config", :task_list => [t1, t2, t3])
|
||||
@cli.options[:verbose] = 1
|
||||
@cli.stubs(:puts)
|
||||
@cli.expects(:puts).with { |s,| (s || "").include?("[internal]") || s =~ /#\s*$/ }.at_least_once
|
||||
@cli.task_list(config)
|
||||
end
|
||||
|
||||
def test_explain_task_should_warn_if_task_does_not_exist
|
||||
config = mock("config", :find_task => nil)
|
||||
@cli.expects(:warn).with { |s,| s =~ /`deploy_with_niftiness'/ }
|
||||
|
@ -96,7 +126,7 @@ class CLIHelpTest < Test::Unit::TestCase
|
|||
|
||||
private
|
||||
|
||||
def task(name, fqn=name)
|
||||
stub("task", :name => name, :fully_qualified_name => fqn)
|
||||
def task(name, fqn=name, desc="a description")
|
||||
stub("task", :name => name, :fully_qualified_name => fqn, :description => desc)
|
||||
end
|
||||
end
|
|
@ -80,10 +80,11 @@ class CLIOptionsTest < Test::Unit::TestCase
|
|||
assert_equal "bar", @cli.options[:vars][:foo]
|
||||
end
|
||||
|
||||
def test_parse_options_with_T_should_set_tasks_option
|
||||
def test_parse_options_with_T_should_set_tasks_option_and_set_verbose_off
|
||||
@cli.args << "-T"
|
||||
@cli.parse_options!
|
||||
assert @cli.options[:tasks]
|
||||
assert_equal 0, @cli.options[:verbose]
|
||||
end
|
||||
|
||||
def test_parse_options_with_V_should_show_version_and_exit
|
||||
|
@ -130,7 +131,7 @@ class CLIOptionsTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_parse_options_without_q_or_v_should_set_verbose_to_3
|
||||
@cli.args << "-T"
|
||||
@cli.args << "-x"
|
||||
@cli.parse_options!
|
||||
assert_equal 3, @cli.options[:verbose]
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue