Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated -T option to take a pattern that matches against fully_qualif…

…ied_name, like Rake.
  • Loading branch information...
commit 0dd68b268dbebccd31b56b4c286dbd1e02c4800f 1 parent 8137d94
@topfunky topfunky authored jamis committed
View
2  CHANGELOG.rdoc
@@ -10,7 +10,7 @@
* Make sure git query-revision matches on exact branch name [grant@nightriot.com]
-* Use -T <arg> to filter listed tasks by namespace [Mathias Meyer]
+* Use -T <arg> to filter listed tasks by a pattern [Mathias Meyer, Geoffrey Grosenbach]
* Expose the #scm method on SCM::Base for building custom scm commands [Mathias Meyer]
View
10 lib/capistrano/cli/help.rb
@@ -20,10 +20,12 @@ def execute_requested_actions_with_help(config)
end
end
- def task_list(config, namespace = true) #:nodoc:
- if namespace.is_a?(String) && config.namespaces[namespace.to_sym]
- tasks = config.namespaces[namespace.to_sym].task_list(:all)
- else
+ def task_list(config, pattern = true) #:nodoc:
+ if pattern.is_a?(String)
+ tasks = config.task_list(:all).select {|t| t.fully_qualified_name =~ /#{pattern}/}
+ end
+ if tasks.nil? || tasks.length == 0
+ puts "Pattern '#{pattern}' not found. Listing all tasks.\n\n" unless pattern.is_a?(TrueClass)
tasks = config.task_list(:all)
end
View
4 lib/capistrano/cli/help.txt
@@ -43,8 +43,8 @@ The following options are understood:
<%= color '-s, --set NAME=VALUE', :bold %>
Sets the given variable to the given value, after loading all recipe files. This is useful when you want to override the value of a variable which is used in a task. Note that this will set the variables too late for them to affect conditions that are executed as the recipes are loaded.
- <%= color '-T, --tasks', :bold %>
- Displays the list of all tasks in all loaded recipe files. If a task has no description, or if the description starts with the [internal] tag, the task will not be listed unless you also specify -v.
+ <%= color '-T, --tasks PATTERN', :bold %>
+ Displays the list of all tasks (matching optional PATTERN) in all loaded recipe files. If a task has no description, or if the description starts with the [internal] tag, the task will not be listed unless you also specify -v.
<%= color '-V, --version', :bold %>
Shows the current Capistrano version number and exits.
View
4 lib/capistrano/cli/options.rb
@@ -79,8 +79,8 @@ def option_parser #:nodoc:
options[:vars][name.to_sym] = value
end
- opts.on("-T", "--tasks [NAMESPACE]",
- "List all tasks in the loaded recipe files."
+ opts.on("-T", "--tasks [PATTERN]",
+ "List all tasks (matching optional PATTERN) in the loaded recipe files."
) do |value|
options[:tasks] = if value
value
View
39 test/cli/help_test.rb
@@ -57,47 +57,37 @@ def test_task_list_should_query_all_tasks_in_all_namespaces
expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
task_list = [task("c"), task("g", "c:g"), task("b", "c:b"), task("a")]
task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name) }
-
+
config = mock("config")
config.expects(:task_list).with(:all).returns(task_list)
@cli.stubs(:puts)
@cli.task_list(config)
end
- def test_task_list_should_query_tasks_in_namespace
+ def test_task_list_should_query_tasks_with_pattern
expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
task_list = [task("g", "c:g"), task("b", "c:b")]
task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name)}
- namespace = mock("namespace")
- namespace.expects(:task_list).with(:all).returns(task_list)
-
- namespaces = mock("namespaces")
- namespaces.expects(:[]).with(:c).times(2).returns(namespace)
config = mock("config")
- config.expects(:namespaces).times(2).returns(namespaces)
-
+ config.expects(:task_list).with(:all).once.returns(task_list)
+
@cli.stubs(:puts)
@cli.task_list(config, "c")
end
- def test_task_list_should_query_for_all_tasks_when_namespace_doesnt_exist
+ def test_task_list_should_query_for_all_tasks_when_pattern_doesnt_match
expected_max_len = 80 - 3 - MockCLI::LINE_PADDING
task_list = [task("g", "c:g"), task("b", "c:b")]
- task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name)}
+ task_list.each { |t| t.expects(:brief_description).with(expected_max_len).returns(t.fully_qualified_name) }
- namespaces = mock("namespaces")
- namespaces.expects(:[]).with(:c).returns(nil)
-
config = mock("config")
- config.expects(:namespaces).returns(namespaces)
-
- config.expects(:task_list).with(:all).returns(task_list)
-
+ config.expects(:task_list).with(:all).times(2).returns(task_list)
+
@cli.stubs(:puts)
- @cli.task_list(config, "c")
+ @cli.task_list(config, "z")
end
-
+
def test_task_list_should_never_use_less_than_MIN_MAX_LEN_chars_for_descriptions
@ui.stubs(:output_cols).returns(20)
t = task("c")
@@ -167,7 +157,8 @@ def test_long_help_should_load_and_format_help_txt_file
private
- def task(name, fqn=name, desc="a description")
- stub("task", :name => name, :fully_qualified_name => fqn, :description => desc)
- end
-end
+ def task(name, fqn=name, desc="a description")
+ stub("task", :name => name, :fully_qualified_name => fqn, :description => desc)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.