diff --git a/README.md b/README.md index 6b16aaf..c5cbe46 100644 --- a/README.md +++ b/README.md @@ -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 \ @@ -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] @@ -242,6 +242,7 @@ imports = [ exclude_tables = [ "comments" ] +column_sort = "preserve-order" ``` ## Sponsorship diff --git a/paracelsus/cli.py b/paracelsus/cli.py index 22e0186..0cf7856 100644 --- a/paracelsus/cli.py +++ b/paracelsus/cli.py @@ -12,6 +12,8 @@ app = typer.Typer() +PYPROJECT_SETTINGS = get_pyproject_settings() + class Formats(str, Enum): mermaid = "mermaid" @@ -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 @@ -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) @@ -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( @@ -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: