diff --git a/dotbot/context.py b/dotbot/context.py index 9820757..cb2b5df 100644 --- a/dotbot/context.py +++ b/dotbot/context.py @@ -1,12 +1,13 @@ import copy import os +from argparse import Namespace class Context(object): ''' Contextual data and information for plugins. ''' - def __init__(self, base_directory, options): + def __init__(self, base_directory, options=Namespace()): self._base_directory = base_directory self._defaults = {} self._options = options @@ -28,6 +29,4 @@ class Context(object): return copy.deepcopy(self._defaults) def options(self): - if self._options is not None: - return copy.deepcopy(self._options) - return None + return copy.deepcopy(self._options) diff --git a/dotbot/dispatcher.py b/dotbot/dispatcher.py index fa38092..c5a21ac 100644 --- a/dotbot/dispatcher.py +++ b/dotbot/dispatcher.py @@ -1,19 +1,16 @@ import os +from argparse import Namespace from .plugin import Plugin from .messenger import Messenger from .context import Context class Dispatcher(object): - def __init__(self, base_directory, only=None, skip=None, options=None): + def __init__(self, base_directory, only=None, skip=None, options=Namespace()): self._log = Messenger() self._setup_context(base_directory, options) self._load_plugins() - if options is not None: - self._only = options.only - self._skip = options.skip - else: - self._only = only - self._skip = skip + self._only = options.only or only + self._skip = options.skip or skip def _setup_context(self, base_directory, options): path = os.path.abspath( diff --git a/test/tests/plugin.bash b/test/tests/plugin.bash index 47e348d..1e113b7 100644 --- a/test/tests/plugin.bash +++ b/test/tests/plugin.bash @@ -40,9 +40,6 @@ class Test(dotbot.Plugin): def handle(self, directive, data): self._log.debug("Attempting to get options from Context") options = self._context.options() - if options is None: - self._log.debug("Context.options is None, expected not None") - return False if len(options.plugins) != 1: self._log.debug("Context.options.plugins length is %i, expected 1" % len(options.plugins)) return False