Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

choose template straight from cli #22

Merged
merged 9 commits into from
Jun 4, 2013
3 changes: 2 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Template Options

-t <ARG1>, --template=<ARG1>
Path to your custom template, absolute paths only, git repositories can also be specified by prefixing with git+
for example: [email protected]/path/to/repo.git
for example: [email protected]/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
Expand Down
5 changes: 5 additions & 0 deletions src/facio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
1 change: 1 addition & 0 deletions tests/test_cfgs/multiple_templates.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[template]
[email protected]:krak3n/Facio-Default-Template.git
another_template=/path/to/template
foo=/path/to/template/foo
23 changes: 23 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down