From 3661aacead5358e0510ea9a225fb819fd02e2ffd Mon Sep 17 00:00:00 2001 From: Javier Delgado Date: Fri, 6 Nov 2015 14:00:55 +0100 Subject: [PATCH] cli: changed startproject command * Changed CLI command start project, which creates a skeleton of a new invenio site, to 'instance create'. (closes #28) Signed-off-by: Javier Delgado --- invenio_base/__init__.py | 10 +++++----- invenio_base/app.py | 4 ++-- invenio_base/cmd.py | 9 +++++++-- tests/test_cmd.py | 15 ++++++++------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/invenio_base/__init__.py b/invenio_base/__init__.py index 8a9f822..8ae4e6e 100644 --- a/invenio_base/__init__.py +++ b/invenio_base/__init__.py @@ -42,9 +42,9 @@ --help Show this message and exit. Commands: - run Runs a development server. - shell Runs a shell in the app context. - startproject Create a new project from template. + run Runs a development server. + shell Runs a shell in the app context. + instance create Create a new project from template. The ``run`` and ``shell`` commands only works if you have specified the @@ -55,12 +55,12 @@ Starting a new project ~~~~~~~~~~~~~~~~~~~~~~ -The ``startproject`` subcommand helps you bootstrap a minimal Invenio +The ``instance create`` subcommand helps you bootstrap a minimal Invenio application: .. code-block:: console - $ inveniomanage startproject mysite + $ inveniomanage instance create mysite $ find mysite diff --git a/invenio_base/app.py b/invenio_base/app.py index b6e6d04..02c5cb2 100644 --- a/invenio_base/app.py +++ b/invenio_base/app.py @@ -35,7 +35,7 @@ from flask import Flask from flask_cli import FlaskCLI, FlaskGroup -from .cmd import startproject +from .cmd import instance def create_app_factory(app_name, conf_loader=None, @@ -145,7 +145,7 @@ def cli(**params): pass # Add command for startin new Invenio instances. - cli.add_command(startproject) + cli.add_command(instance) return cli diff --git a/invenio_base/cmd.py b/invenio_base/cmd.py index c2affe3..da6f3ea 100644 --- a/invenio_base/cmd.py +++ b/invenio_base/cmd.py @@ -30,9 +30,14 @@ from pkg_resources import resource_filename -@click.command() +@click.group() +def instance(): + """Instance commands.""" + + +@instance.command('create') @click.argument('name') -def startproject(name): +def create(name): """Create a new project from template.""" path = resource_filename(__name__, "cookiecutter-invenio-base") diff --git a/tests/test_cmd.py b/tests/test_cmd.py index 1c23ece..d9f3c5e 100644 --- a/tests/test_cmd.py +++ b/tests/test_cmd.py @@ -30,35 +30,36 @@ from click.testing import CliRunner -from invenio_base.cmd import startproject +from invenio_base.cmd import instance -def test_startproject(): +def test_instance_create(): """Test startproject command.""" runner = CliRunner() # Missing arg - result = runner.invoke(startproject, []) + result = runner.invoke(instance, ['create']) assert result.exit_code != 0 # With arg with runner.isolated_filesystem(): - result = runner.invoke(startproject, ['mysite']) + result = runner.invoke(instance, ['create', 'mysite']) assert result.exit_code == 0 -def test_startproject_created_project(): +def test_instance_create_created_project(): """Test startproject command checking the result project.""" runner = CliRunner() # Missing arg - result = runner.invoke(startproject, []) + result = runner.invoke(instance, ['create']) assert result.exit_code != 0 # With arg with runner.isolated_filesystem(): site_name = 'mysite2' - result = runner.invoke(startproject, [site_name]) + result = runner.invoke(instance, ['create', site_name]) + assert result.exit_code == 0 path_to_folder = os.path.join(os.getcwd(), site_name) path_to_manage = os.path.join(path_to_folder, 'manage.py') assert call(['python', path_to_manage]) == 0