Skip to content
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
81 changes: 40 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ $ newt [OPTIONS] COMMAND [ARGS]...

**Options**:

* `-v, --version`: Show version and exit
* `--install-completion`: Install completion for the current shell.
* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
* `--help`: Show this message and exit.
- `-v, --version`: Show version and exit
- `--install-completion`: Install completion for the current shell.
- `--show-completion`: Show completion for the current shell, to copy it or customize the installation.
- `--help`: Show this message and exit.

**Commands**:

* `users`
* `make`
* `config`
* `migrate`
- `users`
- `make`
- `config`
- `migrate`

## `newt users`

Expand All @@ -34,12 +34,12 @@ $ newt users [OPTIONS] COMMAND [ARGS]...

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

**Commands**:

* `add`
* `delete`
- `add`
- `delete`

### `newt users add`

Expand All @@ -51,11 +51,11 @@ $ newt users add [OPTIONS] NAME

**Arguments**:

* `NAME`: [required]
- `NAME`: [required]

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

### `newt users delete`

Expand All @@ -67,11 +67,11 @@ $ newt users delete [OPTIONS] NAME

**Arguments**:

* `NAME`: [required]
- `NAME`: [required]

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

## `newt make`

Expand All @@ -83,11 +83,11 @@ $ newt make [OPTIONS] COMMAND [ARGS]...

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

**Commands**:

* `route`: Generate a new route file with boilerplate...
- `route`: Generate a new route file with boilerplate...

### `newt make route`

Expand All @@ -101,10 +101,10 @@ $ newt make route [OPTIONS]

**Options**:

* `--name TEXT`: Name of the route to create
* `--version TEXT`: API version [default: v1]
* `--path TEXT`: Custom path for the route
* `--help`: Show this message and exit.
- `--name TEXT`: Name of the route to create
- `--version TEXT`: API version [default: v1]
- `--path TEXT`: Custom path for the route
- `--help`: Show this message and exit.

## `newt config`

Expand All @@ -116,11 +116,11 @@ $ newt config [OPTIONS] COMMAND [ARGS]...

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

**Commands**:

* `init`: Create a default newt-cli.conf file if...
- `init`: Create a default newt-cli.conf file if...

### `newt config init`

Expand All @@ -134,7 +134,7 @@ $ newt config init [OPTIONS]

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

## `newt migrate`

Expand All @@ -146,23 +146,22 @@ $ newt migrate [OPTIONS] COMMAND [ARGS]...

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

**Commands**:

* `init`: Checks if alembic is already initialized...
* `up`: Upgrades the database to the specified...
* `down`: Downgrades the database to the specified...
* `make`: Creates a new migration file.
- `init`: Checks if alembic is already initialized...
- `up`: Upgrades the database to the specified...
- `down`: Downgrades the database to the specified...
- `make`: Creates a new migration file.

### `newt migrate init`

Checks if alembic is already initialized in the current directory.
If not then it checks if alembic is installed. If not then it will prompt the user to install it.
After installing alembic it will create a new alembic directory in the current or given path.
If alembic is already initialized in the current directory then it will ask if the user wants to reinitialize it.
If the user chooses to reinitialize it, it will remove the existing alembic directory and create a new one.
If the user chooses not to reinitialize it, it will exit the program.
Otherwise, it will create a new alembic directory in the current or given path.

**Usage**:

Expand All @@ -172,12 +171,12 @@ $ newt migrate init [OPTIONS] [PATH]

**Arguments**:

* `[PATH]`: Relative path to the alembic directory [default: alembic]
- `[PATH]`: Relative path to the alembic directory [default: alembic]

**Options**:

* `-t, --template TEXT`: Custom template for the alembic directory
* `--help`: Show this message and exit.
- `-t, --template TEXT`: Custom template for the alembic directory
- `--help`: Show this message and exit.

### `newt migrate up`

Expand All @@ -194,11 +193,11 @@ $ newt migrate up [OPTIONS] [REVISION]

**Arguments**:

* `[REVISION]`: Revision to upgrade to
- `[REVISION]`: Revision to upgrade to

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

### `newt migrate down`

Expand All @@ -215,11 +214,11 @@ $ newt migrate down [OPTIONS] [REVISION]

**Arguments**:

* `[REVISION]`: Revision to downgrade to
- `[REVISION]`: Revision to downgrade to

**Options**:

* `--help`: Show this message and exit.
- `--help`: Show this message and exit.

### `newt migrate make`

Expand All @@ -235,9 +234,9 @@ $ newt migrate make [OPTIONS] MESSAGE

**Arguments**:

* `MESSAGE`: Message for the migration file [required]
- `MESSAGE`: Message for the migration file [required]

**Options**:

* `-m, --manual`: Disable auto generation of migration files
* `--help`: Show this message and exit.
- `-m, --manual`: Disable auto generation of migration files
- `--help`: Show this message and exit.
34 changes: 8 additions & 26 deletions newt/commands/migrate/init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import shutil
import subprocess
from pathlib import Path
from typing import Annotated

import typer
from pathlib import Path
from newt.config import config_values

app = typer.Typer(no_args_is_help=True)

Expand All @@ -11,29 +13,11 @@ def init(
template: Annotated[str, typer.Option("--template", "-t", help="Custom template for the alembic directory")] = None,
):
"""
Checks if alembic is already initialized in the current directory.
If not then it checks if alembic is installed. If not then it will prompt the user to install it.
After installing alembic it will create a new alembic directory in the current or given path.
If alembic is already initialized in the current directory then it will ask if the user wants to reinitialize it.
If the user chooses to reinitialize it, it will remove the existing alembic directory and create a new one.
If the user chooses not to reinitialize it, it will exit the program.
Creates a new alembic directory in the current or given path.
If alembic is already initialized in the specified directory, it will ask if the user wants to reinitialize it.
If the user chooses to reinitialize, it will remove the existing alembic directory and create a new one.
If the user chooses not to reinitialize, it will exit the program.
"""
# Check if alembic is already initialized via pip
is_installed = True
try:
import alembic
except ImportError:
is_installed = False

if not is_installed:
# Install alembic
install = typer.confirm("Alembic is not installed. Do you want to install it?")
if not install:
raise typer.Abort()
else:
import subprocess
subprocess.run(["pip", "install", "alembic"])

# Check if alembic is already initialized in the current directory
project_dir = Path(f"{Path.cwd()}/{path}")

Expand All @@ -43,7 +27,6 @@ def init(
if not reinitialize:
raise typer.Abort()
else:
import shutil
shutil.rmtree(project_dir)
project_dir.mkdir(parents=True, exist_ok=True)

Expand All @@ -53,6 +36,5 @@ def init(
command.extend(["--template", template])

# Run alembic init command from a subfolder
import subprocess
subprocess.run(command)

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"typer>=0.20.0",
"alembic>=1.8.0",
]

[project.scripts]
newt = "newt.main:app"
Loading