Skip to content

Commit

Permalink
Merge pull request #20 from tedivm/cli_pyproject_additions
Browse files Browse the repository at this point in the history
Fix help messages and add sort to pyproject.toml
  • Loading branch information
tedivm authored Jun 9, 2024
2 parents 3620fb6 + 8353a7a commit 33adc44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ paracelsus graph example_app.models.base:Base \
### Specify Column Sort Order

By default Paracelsus will sort the columns in all models such as primary keys are first, foreign keys are next and all other
columns are sorted alphabetically by name.
columns are sorted alphabetically by name.

```bash
paracelsus graph example_app.models.base:Base \
Expand Down Expand Up @@ -231,7 +231,7 @@ imports = [
]
```

This also works with excludes and includes.
This also allows users to set excludes, includes, and column sorting.

```toml
[tool.paracelsus]
Expand All @@ -242,6 +242,7 @@ imports = [
exclude_tables = [
"comments"
]
column_sort = "preserve-order"
```

## Sponsorship
Expand Down
16 changes: 12 additions & 4 deletions paracelsus/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

app = typer.Typer()

PYPROJECT_SETTINGS = get_pyproject_settings()


class Formats(str, Enum):
mermaid = "mermaid"
Expand All @@ -25,6 +27,12 @@ class ColumnSorts(str, Enum):
preserve = "preserve-order"


if "column_sort" in PYPROJECT_SETTINGS:
SORT_DEFAULT = ColumnSorts(PYPROJECT_SETTINGS["column_sort"]).value
else:
SORT_DEFAULT = ColumnSorts.key_based.value


def get_base_class(base_class_path: str | None, settings: Dict[str, Any] | None) -> str:
if base_class_path:
return base_class_path
Expand Down Expand Up @@ -67,13 +75,13 @@ def graph(
] = [],
format: Annotated[
Formats, typer.Option(help="The file format to output the generated graph to.")
] = Formats.mermaid,
] = Formats.mermaid.value, # type: ignore # Typer will fail to render the help message, but this code works.
column_sort: Annotated[
ColumnSorts,
typer.Option(
help="Specifies the method of sorting columns in diagrams.",
),
] = ColumnSorts.key_based,
] = SORT_DEFAULT, # type: ignore # Typer will fail to render the help message, but this code works.
):
settings = get_pyproject_settings()
base_class = get_base_class(base_class_path, settings)
Expand Down Expand Up @@ -144,7 +152,7 @@ def inject(
] = [],
format: Annotated[
Formats, typer.Option(help="The file format to output the generated graph to.")
] = Formats.mermaid,
] = Formats.mermaid.value, # type: ignore # Typer will fail to render the help message, but this code works.
check: Annotated[
bool,
typer.Option(
Expand All @@ -157,7 +165,7 @@ def inject(
typer.Option(
help="Specifies the method of sorting columns in diagrams.",
),
] = ColumnSorts.key_based,
] = SORT_DEFAULT, # type: ignore # Typer will fail to render the help message, but this code works.
):
settings = get_pyproject_settings()
if "imports" in settings:
Expand Down

0 comments on commit 33adc44

Please sign in to comment.