diff --git a/docs/usage.rst b/docs/usage.rst index dc7cf50..0e4168a 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -47,7 +47,8 @@ Template Options -t , --template= Path to your custom template, absolute paths only, git repositories can also be specified by prefixing with git+ - for example: git+git@gitbub.com/path/to/repo.git + for example: git+git@gitbub.com/path/to/repo.git. This can also be the template name you gave a template in the + ``.facio.cfg`` file. -c, --choose_template If you have more than 1 template defined use this flag to override the default template, Note: specifying -t diff --git a/src/facio/config.py b/src/facio/config.py index c55df8b..720c107 100644 --- a/src/facio/config.py +++ b/src/facio/config.py @@ -105,6 +105,11 @@ def project_name(self): # def _validate_template_options(self): + templates = self.file_args.templates + try: + self._tpl = [t for n, t in templates if n == self._tpl][0] + except IndexError: + pass # We don't care if this fails, assume it's a path if (not self._tpl.startswith('git+') and not os.path.isdir(self._tpl)): self._error('The path to your template does not exist.') diff --git a/tests/test_cfgs/multiple_templates.cfg b/tests/test_cfgs/multiple_templates.cfg index b1c2136..66d03e0 100644 --- a/tests/test_cfgs/multiple_templates.cfg +++ b/tests/test_cfgs/multiple_templates.cfg @@ -1,3 +1,4 @@ [template] default=git+git@github.com:krak3n/Facio-Default-Template.git another_template=/path/to/template +foo=/path/to/template/foo diff --git a/tests/test_config.py b/tests/test_config.py index cd52931..3b22394 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -139,6 +139,29 @@ def test_value_error_raised_on_zero_template_choice(self): except SystemExit: assert True + @patch('os.path.isdir', return_value=True) + @patch('facio.config.ConfigFile.path', new_callable=PropertyMock) + def test_can_refernce_template_by_name_from_cli( + self, + mock_path, + mock_isdir): + mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') + try: + self._set_cli_args(self.base_args + ['-t', 'foo']) + self.config = Config() + self.assertEquals(self.config.template, '/path/to/template/foo') + except SystemExit: + assert False + + @patch('facio.config.ConfigFile.path', new_callable=PropertyMock) + def test_can_refernce_template_by_name_from_cli_invalid(self, mock_path): + mock_path.return_value = self._test_cfg_path('multiple_templates.cfg') + try: + self._set_cli_args(self.base_args + ['-t', 'not_valid_name']) + Config() + except SystemExit: + assert True + def test_cache_django_secret_key(self): sys.argv = sys.argv + self.base_args self.config = Config()