Skip to content

Commit

Permalink
Add project slug name to neuro project init (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
anayden authored Dec 17, 2019
1 parent 8d39906 commit fcd9ee2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
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)

0 comments on commit fcd9ee2

Please sign in to comment.