Permalink
Browse files

Add option to skip unknown tasks

  • Loading branch information...
1 parent d243ebb commit f5aede982b8f42910f97236ea9ee4fefb2e8b4c3 @lundberg lundberg committed Mar 5, 2014
Showing with 47 additions and 2 deletions.
  1. +1 −0 AUTHORS
  2. +1 −1 fabric/main.py
  3. +6 −0 fabric/state.py
  4. +6 −1 fabric/tasks.py
  5. +14 −0 sites/docs/usage/env.rst
  6. +8 −0 sites/docs/usage/fab.rst
  7. +2 −0 sites/www/changelog.rst
  8. +9 −0 tests/test_tasks.py
View
@@ -57,3 +57,4 @@ Neilen Marais
Rory Geoghegan
Alexey Diyan
Kamil Kisiel
+Jonas Lundberg
View
@@ -709,7 +709,7 @@ def main(fabfile_locations=None):
unknown_commands.append(tup[0])
# Abort if any unknown commands were specified
- if unknown_commands:
+ if unknown_commands and not state.env.get('skip_unknown_tasks', False):
warn("Command(s) not found:\n%s" \
% indent(unknown_commands))
show_commands(None, options.list_format, 1)
View
@@ -243,6 +243,12 @@ def _rc_path():
help="skip over hosts that can't be reached"
),
+ make_option('--skip-unknown-tasks',
+ action="store_true",
+ default=False,
+ help="skip over unknown tasks"
+ ),
+
make_option('--ssh-config-path',
default=default_ssh_config_path,
metavar='PATH',
View
@@ -330,7 +330,12 @@ def execute(task, *args, **kwargs):
my_env['command'] = task
task = crawl(task, state.commands)
if task is None:
- abort("%r is not callable or a valid task name" % (task,))
+ msg = "%r is not callable or a valid task name" % (my_env['command'],)
+ if state.env.get('skip_unknown_tasks', False):
+ warn(msg)
+ return
+ else:
+ abort(msg)
# Set env.command if we were given a real function or callable task obj
else:
dunder_name = getattr(task, '__name__', None)
@@ -708,6 +708,20 @@ If ``True``, causes ``fab`` (or non-``fab`` use of `~fabric.tasks.execute`) to s
:option:`--skip-bad-hosts`, :ref:`excluding-hosts`, :doc:`execution`
+.. _skip-unknown-tasks:
+
+``skip_unknown_tasks``
+----------------------
+
+**Default:** ``False``
+
+If ``True``, causes ``fab`` (or non-``fab`` use of `~fabric.tasks.execute`)
+to skip over tasks not found, without aborting.
+
+.. seealso::
+ :option:`--skip-unknown-tasks`
+
+
.. _ssh-config-path:
``ssh_config_path``
@@ -320,6 +320,14 @@ below.
.. versionadded:: 1.4
+.. cmdoption:: --skip-unknown-tasks
+
+ Sets :ref:`env.skip_unknown_tasks <skip-unknown-tasks>`, causing Fabric to skip
+ unknown tasks.
+
+ .. seealso::
+ :ref:`env.skip_unknown_tasks <skip-unknown-tasks>`
+
.. cmdoption:: --timeout=N, -t N
Set connection timeout in seconds. Sets :ref:`env.timeout <timeout>`.
@@ -2,6 +2,8 @@
Changelog
=========
+* :feature:`1090` Add option to skip unknown tasks.
+ Thanks to Jonas Lundberg, `@lundberg`
* :release:`1.9.1 <2014-08-06>`
* :release:`1.8.5 <2014-08-06>`
* :release:`1.7.5 <2014-08-06>`
View
@@ -211,6 +211,15 @@ def test_should_abort_if_task_name_not_found(self):
"""
execute('thisisnotavalidtaskname')
+ def test_should_not_abort_if_task_name_not_found_with_skip(self):
+ """
+ should not abort if given an invalid task name
+ and skip_unknown_tasks in env
+ """
+ env.skip_unknown_tasks = True
+ execute('thisisnotavalidtaskname')
+ del env['skip_unknown_tasks']
+
@with_fakes
def test_should_pass_through_args_kwargs(self):
"""

0 comments on commit f5aede9

Please sign in to comment.