From 7ffaa65482a59fa485e7a8f19fe07a33694fc157 Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Wed, 25 Mar 2020 21:38:39 -0400 Subject: 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. --- dotbot/cli.py | 6 +++++- dotbot/dispatcher.py | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'dotbot') 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 -- cgit v1.2.3