Skip to content

Commit

Permalink
Merge pull request #77 from cicekhayri/add-only-controller-flag
Browse files Browse the repository at this point in the history
Refactor directory path generation for clarity and conciseness
  • Loading branch information
cicekhayri authored Jan 31, 2024
2 parents dc5746c + 99c32fb commit ed19def
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 3 additions & 2 deletions inspira/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ def migrate(down):


@cli.command()
def init():
generate_project()
@click.option("--only-controller", "only_controller", is_flag=True, required=False, help="Generates only controller module")
def init(only_controller):
generate_project(only_controller)
click.echo("App file created successfully.")


Expand Down
24 changes: 12 additions & 12 deletions inspira/cli/create_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import click

from inspira.cli.init_file import create_init_file
from inspira.constants import SRC_DIRECTORY
from inspira.constants import SRC_DIRECTORY, INIT_DOT_PY
from inspira.utils import get_random_secret_key


def generate_project():
def generate_project(only_controller):
create_app_file()
create_directory_structure()
create_directory_structure(only_controller)
create_test_directory()
click.echo("Project created successfully")

Expand All @@ -21,21 +21,21 @@ def create_test_directory():
create_init_file(test_directory)


def create_directory_structure():
def create_directory_structure(only_controller):
base_dir = SRC_DIRECTORY
dirs = [
base_dir,
os.path.join(base_dir, "__init__.py"),
os.path.join(base_dir, INIT_DOT_PY),
os.path.join(base_dir, "controller"),
os.path.join(base_dir, "controller", "__init__.py"),
os.path.join(base_dir, "model"),
os.path.join(base_dir, "model", "__init__.py"),
os.path.join(base_dir, "repository"),
os.path.join(base_dir, "repository", "__init__.py"),
os.path.join(base_dir, "service"),
os.path.join(base_dir, "service", "__init__.py"),
os.path.join(base_dir, "controller", INIT_DOT_PY),
]

if not only_controller:
subdirectories = ["model", "repository", "service"]
for subdirectory in subdirectories:
dirs.append(os.path.join(base_dir, subdirectory))
dirs.append(os.path.join(base_dir, subdirectory, INIT_DOT_PY))

for dir_path in dirs:
if not os.path.exists(dir_path):
if "." in dir_path:
Expand Down
1 change: 1 addition & 0 deletions inspira/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@

SRC_DIRECTORY = "src"
MIGRATION_DIRECTORY = "migrations"
INIT_DOT_PY = "__init__.py"

0 comments on commit ed19def

Please sign in to comment.