Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added ability to list only task in a specified namespace

  • Loading branch information...
commit 96cb5ab7e771a34e625a80e394a02acb8be3187f 1 parent 0a1110b
@roidrage roidrage authored jamis committed
View
4 CHANGELOG.rdoc
@@ -1,5 +1,9 @@
== (unreleased)
+* Use -T <arg> to filter listed tasks by namespace [Mathias Meyer]
+
+* Expose the #scm method on SCM::Base for building custom scm commands [Mathias Meyer]
+
* Start logging some locally executed commands [springyweb]
* Added HOSTFILTER environment variable for constraining tasks so they run only on hosts matching the given list of servers [Walter Smith]
View
12 lib/capistrano/cli/help.rb
@@ -12,7 +12,7 @@ def self.included(base) #:nodoc:
def execute_requested_actions_with_help(config)
if options[:tasks]
- task_list(config)
+ task_list(config, options[:tasks])
elsif options[:explain]
explain_task(config, options[:explain])
else
@@ -20,8 +20,12 @@ def execute_requested_actions_with_help(config)
end
end
- def task_list(config) #:nodoc:
- tasks = config.task_list(:all)
+ 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
+ tasks = config.task_list(:all)
+ end
if tasks.empty?
warn "There are no tasks available. Please specify a recipe file to load."
@@ -45,7 +49,7 @@ def task_list(config) #:nodoc:
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 `#{File.basename($0)} -Tv'."
+ puts "tasks, type `#{File.basename($0)} -vT'."
end
puts
View
10 lib/capistrano/cli/options.rb
@@ -79,10 +79,14 @@ def option_parser #:nodoc:
options[:vars][name.to_sym] = value
end
- opts.on("-T", "--tasks",
+ opts.on("-T", "--tasks [NAMESPACE]",
"List all tasks in the loaded recipe files."
- ) do
- options[:tasks] = true
+ ) do |value|
+ options[:tasks] = if value
+ value
+ else
+ true
+ end
options[:verbose] ||= 0
end
View
36 test/cli/help_test.rb
@@ -33,7 +33,7 @@ def test_execute_requested_actions_without_tasks_or_explain_should_call_original
def test_execute_requested_actions_with_tasks_should_call_task_list
@cli.options[:tasks] = true
- @cli.expects(:task_list).with(:config)
+ @cli.expects(:task_list).with(:config, true)
@cli.expects(:explain_task).never
@cli.execute_requested_actions(:config)
assert !@cli.called_original
@@ -64,6 +64,40 @@ def test_task_list_should_query_all_tasks_in_all_namespaces
@cli.task_list(config)
end
+ def test_task_list_should_query_tasks_in_namespace
+ 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)
+
+ @cli.stubs(:puts)
+ @cli.task_list(config, "c")
+ end
+
+ def test_task_list_should_query_for_all_tasks_when_namespace_doesnt_exist
+ 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)}
+
+ 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)
+
+ @cli.stubs(:puts)
+ @cli.task_list(config, "c")
+ 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")
Please sign in to comment.
Something went wrong with that request. Please try again.