summaryrefslogtreecommitdiff
path: root/dotbot
diff options
context:
space:
mode:
authorAnish Athalye <me@anishathalye.com>2020-03-25 21:38:39 -0400
committerAnish Athalye <me@anishathalye.com>2020-03-26 11:23:07 -0400
commit7ffaa65482a59fa485e7a8f19fe07a33694fc157 (patch)
tree78e5990b5934b920b797fe7bace046b3b9bf51c6 /dotbot
parent5d83f9e797b1950199e127a8196803f5e33e0916 (diff)
Add --only and --except command-line arguments
Internal to Dotbot, we use the name "skip" instead of "except", because the latter is a keyword, and using a name like "except_" didn't seem as nice.
Diffstat (limited to 'dotbot')
-rw-r--r--dotbot/cli.py6
-rw-r--r--dotbot/dispatcher.py8
2 files changed, 12 insertions, 2 deletions
diff --git a/dotbot/cli.py b/dotbot/cli.py
index 77bd439..258ea87 100644
--- a/dotbot/cli.py
+++ b/dotbot/cli.py
@@ -28,6 +28,10 @@ def add_options(parser):
action='store_true', help='disable built-in plugins')
parser.add_argument('--plugin-dir', action='append', dest='plugin_dirs', default=[],
metavar='PLUGIN_DIR', help='load all plugins in PLUGIN_DIR')
+ parser.add_argument('--only', nargs='+',
+ help='only run specified directives', metavar='DIRECTIVE')
+ parser.add_argument('--except', nargs='+', dest='skip',
+ help='skip specified directives', metavar='DIRECTIVE')
parser.add_argument('--no-color', dest='no_color', action='store_true',
help='disable color output')
parser.add_argument('--version', action='store_true',
@@ -78,7 +82,7 @@ def main():
# default to directory of config file
base_directory = os.path.dirname(os.path.abspath(options.config_file))
os.chdir(base_directory)
- dispatcher = Dispatcher(base_directory)
+ dispatcher = Dispatcher(base_directory, only=options.only, skip=options.skip)
success = dispatcher.dispatch(tasks)
if success:
log.info('\n==> All tasks executed successfully')
diff --git a/dotbot/dispatcher.py b/dotbot/dispatcher.py
index 36eac02..10e4293 100644
--- a/dotbot/dispatcher.py
+++ b/dotbot/dispatcher.py
@@ -4,10 +4,12 @@ from .messenger import Messenger
from .context import Context
class Dispatcher(object):
- def __init__(self, base_directory):
+ def __init__(self, base_directory, only=None, skip=None):
self._log = Messenger()
self._setup_context(base_directory)
self._load_plugins()
+ self._only = only
+ self._skip = skip
def _setup_context(self, base_directory):
path = os.path.abspath(
@@ -20,6 +22,10 @@ class Dispatcher(object):
success = True
for task in tasks:
for action in task:
+ if self._only is not None and action not in self._only \
+ or self._skip is not None and action in self._skip:
+ self._log.info('Skipping action %s' % action)
+ continue
handled = False
if action == 'defaults':
self._context.set_defaults(task[action]) # replace, not update