Public repository: timo / mitch

Reader

A migration stitcher (therefore mitch) for PostgreSQL, SQLite, MariaDB, and others

fix(cli): clean up help texts

public

fix(cli): clean up help texts

- show "current directory" as the default of --project instead of
  a bound method or (dynamic)
- drop the <class 'list'> default of create --dependency
- describe stash and status in `mitch --help`
- mention MITCH_DATABASE_URL/DATABASE_URL for up and add
- help for create's argument; ADR reference out of rework's summary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changeseta47913f38316600198945d131c4ef8e7272d5656
Author (claimed)Timo Stolz <timo.stolz@gmail.com>,
Parents96cfa8ba2d2e
Children
Pushlog
by timo via ssh

modified src/mitch/cli/checkout.py +2 −1

@@ -41,7 +41,8 @@
4141
             "--project",
4242
             "-p",
4343
             help="Project directory.",
44
-            default_factory=lambda: Path.cwd(),
44
+            default_factory=Path.cwd,
45
+            show_default="current directory",
4546
             dir_okay=True,
4647
             file_okay=False,
4748
             exists=True,

modified src/mitch/cli/create.py +9 −9

@@ -58,7 +58,7 @@
5858
 
5959
 @app.command()
6060
 def create(
61
-    migration_id: str,
61
+    migration_id: Annotated[str, typer.Argument(help="ID of the new migration. Slashes create subdirectories.")],
6262
     root: Annotated[
6363
         Path,
6464
         typer.Option(
@@ -66,6 +66,7 @@
6666
             "-p",
6767
             help="Project directory.",
6868
             default_factory=Path.cwd,
69
+            show_default="current directory",
6970
             dir_okay=True,
7071
             file_okay=False,
7172
             exists=True,
@@ -74,7 +75,11 @@
7475
     dependencies: Annotated[
7576
         list[str],
7677
         typer.Option(
77
-            "--dependency", "-d", help="IDs of migrations that this migration depends on.", default_factory=list
78
+            "--dependency",
79
+            "-d",
80
+            help="ID of a migration that this migration depends on. Repeat for several.",
81
+            default_factory=list,
82
+            show_default=False,
7883
         ),
7984
     ],
8085
     skip_config: Annotated[
@@ -84,14 +89,9 @@
8489
         bool, typer.Option("--skip-downscript", "-sd", help="Skip creating a downscript for the migration.")
8590
     ] = False,
8691
 ) -> None:
87
-    """Create a new migration scaffold in the project.
92
+    """Create the up script, down script and config of a new migration.
8893
 
89
-    Args:
90
-        migration_id: The ID of the new migration.
91
-
92
-    Stdin:
93
-        Optionally provide SQL via stdin. Use `-- up.sql` / `-- down.sql`
94
-        comment headers to split content between both scripts.
94
+    SQL on stdin fills the scripts: the comment lines `-- up.sql` and `-- down.sql` split it between them.
9595
     """
9696
 
9797
     migration_path = Path(root) / migration_id

modified src/mitch/cli/deploy.py +4 −4

@@ -432,8 +432,8 @@
432432
 @app.command(name="add")
433433
 def add(
434434
     migration_ids: list[str],
435
-    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
436
-    database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database connection URL.")] = None,
435
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=Path.cwd, show_default="current directory", dir_okay=True, file_okay=False, exists=True)],
436
+    database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database URL. Can also be set via MITCH_DATABASE_URL or DATABASE_URL environment variable.")] = None,
437437
     if_modified: Annotated[
438438
         IfModifiedOption | None,
439439
         typer.Option(
@@ -486,8 +486,8 @@
486486
 
487487
 @app.command()
488488
 def up(
489
-    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
490
-    database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database connection URL.")] = None,
489
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=Path.cwd, show_default="current directory", dir_okay=True, file_okay=False, exists=True)],
490
+    database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database URL. Can also be set via MITCH_DATABASE_URL or DATABASE_URL environment variable.")] = None,
491491
     if_modified: Annotated[
492492
         IfModifiedOption | None,
493493
         typer.Option(

modified src/mitch/cli/log.py +2 −1

@@ -41,7 +41,8 @@
4141
             "--project",
4242
             "-p",
4343
             help="Project directory.",
44
-            default_factory=lambda: Path.cwd(),
44
+            default_factory=Path.cwd,
45
+            show_default="current directory",
4546
             dir_okay=True,
4647
             file_okay=False,
4748
             exists=True,

modified src/mitch/cli/revert.py +2 −2

@@ -15,7 +15,7 @@
1515
 
1616
 @app.command(name="down", help="Revert all applied migrations in the project.")
1717
 def down(
18
-    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
18
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=Path.cwd, show_default="current directory", dir_okay=True, file_okay=False, exists=True)],
1919
     database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database URL. Can also be set via MITCH_DATABASE_URL or DATABASE_URL environment variable.")] = None,
2020
 ) -> None:
2121
     """Revert all applied migrations in the project."""
@@ -48,7 +48,7 @@
4848
 )
4949
 def drop(
5050
     migration_ids: list[str],
51
-    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=lambda: Path.cwd(), dir_okay=True, file_okay=False, exists=True)],
51
+    root: Annotated[Path, typer.Option("--project", "-p", help="Project directory.", default_factory=Path.cwd, show_default="current directory", dir_okay=True, file_okay=False, exists=True)],
5252
     database_url: Annotated[str | None, typer.Option("--database", "-d", help="Database URL. Can also be set via MITCH_DATABASE_URL or DATABASE_URL environment variable.")] = None,
5353
 ) -> None:
5454
     """Revert the specified migrations and their dependants in the project.

modified src/mitch/cli/rework.py +4 −1

@@ -29,17 +29,20 @@
2929
             "-p",
3030
             help="Project directory.",
3131
             default_factory=Path.cwd,
32
+            show_default="current directory",
3233
             dir_okay=True,
3334
             file_okay=False,
3435
             exists=True,
3536
         ),
3637
     ],
3738
 ) -> None:
38
-    """Create a new version of a migration (ADR cli/rework/rework-keeps-the-previous-version-in-every-history).
39
+    """Create a new version of a migration.
3940
 
4041
     The current files are archived as `<name>@<n>.*` under their original ID. The files at the original
4142
     path become the new version: a new ID, a dependency on the archived version, ordering constraints on
4243
     its current dependants, and a down script that restores the archived version.
44
+
45
+    See ADR cli/rework/rework-keeps-the-previous-version-in-every-history.
4346
     """
4447
     project = Project.from_path(root)
4548
     if ":" in migration_id and (linked := project.try_resolve(migration_id)) is not None and not project.is_own(linked):

modified src/mitch/cli/stash.py +3 −1

@@ -59,7 +59,8 @@
5959
             "--project",
6060
             "-p",
6161
             help="Project directory.",
62
-            default_factory=lambda: Path.cwd(),
62
+            default_factory=Path.cwd,
63
+            show_default="current directory",
6364
             dir_okay=True,
6465
             file_okay=False,
6566
             exists=True,
@@ -81,6 +82,7 @@
8182
         ),
8283
     ] = None,
8384
 ) -> None:
85
+    """Revert migrations changed in the working copy, stash the changes, and re-apply the committed versions."""
8486
     project = Project.from_path(root)
8587
     vcs_manager = project.get_migration_manager(vcs)
8688
 

modified src/mitch/cli/status.py +3 −1

@@ -108,7 +108,8 @@
108108
             "--project",
109109
             "-p",
110110
             help="Project directory.",
111
-            default_factory=lambda: Path.cwd(),
111
+            default_factory=Path.cwd,
112
+            show_default="current directory",
112113
             dir_okay=True,
113114
             file_okay=False,
114115
             exists=True,
@@ -150,6 +151,7 @@
150151
         ),
151152
     ] = None,
152153
 ) -> None:
154
+    """Show which migrations are available, modified or missing on the database."""
153155
     try:
154156
         project = Project.from_path(root, strict=False)
155157
         for warning in project.warnings: