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

Add project slug name to neuro project init #1254

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.D/1230.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`neuro project init` now supports argument to set default value for generated project directory
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ Initialize an empty project.<br/>
**Usage:**

```bash
neuro project init [OPTIONS]
neuro project init [OPTIONS] [SLUG]
```

**Examples:**
Expand All @@ -703,12 +703,17 @@ neuro project init [OPTIONS]
# structure (see http://github.com/neuromation/cookiecutter-neuro-project)
neuro project init

# Initializes a scaffolding for the new project with the recommended project
# structure and sets default project folder name to "example"
neuro project init example

```

**Options:**

Name | Description|
|----|------------|
|_\-q, --quiet_|Don't ask any questions, use default values for project setup|
|_--help_|Show this message and exit.|


Expand Down
25 changes: 23 additions & 2 deletions neuromation/cli/project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

import click
from cookiecutter.main import cookiecutter

from .root import Root
Expand All @@ -18,7 +19,16 @@ def project() -> None:

@command()
@async_cmd()
async def init(root: Root) -> None:
@click.argument("slug", required=False)
@click.option(
"--quiet",
"-q",
is_flag=True,
required=False,
default=False,
help="Don't ask any questions, use default values for project setup",
)
async def init(root: Root, slug: str, quiet: bool) -> None:
"""
Initialize an empty project.

Expand All @@ -27,8 +37,19 @@ async def init(root: Root) -> None:
# Initializes a scaffolding for the new project with the recommended project
# structure (see http://github.com/neuromation/cookiecutter-neuro-project)
neuro project init

# Initializes a scaffolding for the new project with the recommended project
# structure and sets default project folder name to "example"
neuro project init example
"""
cookiecutter(f"gh:neuromation/cookiecutter-neuro-project")
extra_context = None
if slug:
extra_context = {"project_slug": slug}
cookiecutter(
f"gh:neuromation/cookiecutter-neuro-project",
extra_context=extra_context,
no_input=quiet,
)


project.add_command(init)
30 changes: 30 additions & 0 deletions tests/e2e/test_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pathlib
import shutil

import pytest

from tests.e2e import Helper


@pytest.mark.e2e
def test_project_init(helper: Helper) -> None:
path = pathlib.Path(f"./name-of-the-project")
assert not path.exists()
try:
helper.run_cli(["project", "init", "-q"])
assert path.exists()
assert path.is_dir()
finally:
shutil.rmtree(path)


@pytest.mark.e2e
def test_project_init_custom_slug(helper: Helper) -> None:
path = pathlib.Path("./my-custom-slug")
assert not path.exists()
try:
helper.run_cli(["project", "init", "-q", "my-custom-slug"])
assert path.exists()
assert path.is_dir()
finally:
shutil.rmtree(path)