diff --git a/sigal/__init__.py b/sigal/__init__.py index d2ed407..5f4df59 100644 --- a/sigal/__init__.py +++ b/sigal/__init__.py @@ -49,15 +49,17 @@ from .settings import read_settings _DEFAULT_CONFIG_FILE = 'sigal.conf.py' -def init(): +@arg('path', nargs='?', help='Path of the sample config file') +def init(path): """Copy a sample config file in the current directory.""" from pkg_resources import resource_string + path = path or 'sigal.conf.py' conf = resource_string(__name__, 'templates/sigal.conf.py') - with io.open('sigal.conf.py', 'w', 'utf-8') as f: - f.write(conf) - print("Sample config file created: sigal.conf.py") + with io.open(path, 'w', encoding='utf-8') as f: + f.write(conf.decode('utf8')) + print("Sample config file created: {}".format(path)) @arg('source', nargs='?', help='Input directory') diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..2bfeb16 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +import os +from sigal import init + + +def test_init(tmpdir): + config_file = str(tmpdir.join('sigal.conf.py')) + init(path=config_file) + assert os.path.isfile(config_file)