summaryrefslogtreecommitdiff
path: root/yoyo
diff options
context:
space:
mode:
authorOlly Cope <olly@ollycope.com>2022-11-02 16:34:29 +0000
committerOlly Cope <olly@ollycope.com>2022-11-02 16:34:29 +0000
commit0a886d90b28678a43b8728cb330d6774c2c36e1e (patch)
tree9dce40238b36531254dfa852a6dc614c0adceb9b /yoyo
parent6a01da3deb23af5a98c67e4f120d695a09b3e4bf (diff)
downloadyoyo-0a886d90b28678a43b8728cb330d6774c2c36e1e.tar.gz
scripts: make scripts return an exitcode
Diffstat (limited to 'yoyo')
-rwxr-xr-xyoyo/scripts/main.py6
-rwxr-xr-xyoyo/scripts/migrate.py24
-rw-r--r--yoyo/scripts/newmigration.py5
3 files changed, 23 insertions, 12 deletions
diff --git a/yoyo/scripts/main.py b/yoyo/scripts/main.py
index e6bae2b..fc729b4 100755
--- a/yoyo/scripts/main.py
+++ b/yoyo/scripts/main.py
@@ -301,13 +301,15 @@ def main(argv=None):
try:
if vars(args).get("func"):
- args.func(args, config)
+ exitcode = args.func(args, config)
except InvalidArgument as e:
argparser.error(e.args[0])
if config_is_empty and args.use_config_file and not args.batch_mode:
prompt_save_config(config, args.config or CONFIG_FILENAME)
+ return exitcode
+
if __name__ == "__main__":
- main(sys.argv[1:])
+ sys.exit(main(sys.argv[1:]))
diff --git a/yoyo/scripts/migrate.py b/yoyo/scripts/migrate.py
index 15de7b0..060499a 100755
--- a/yoyo/scripts/migrate.py
+++ b/yoyo/scripts/migrate.py
@@ -256,30 +256,33 @@ def get_migrations(args, backend, direction=None):
return migrations
-def apply(args, config):
+def apply(args, config) -> int:
backend = get_backend(args, config)
with backend.lock():
migrations = get_migrations(args, backend)
backend.apply_migrations(migrations, args.force)
+ return 0
-def reapply(args, config):
+def reapply(args, config) -> int:
backend = get_backend(args, config)
with backend.lock():
migrations = get_migrations(args, backend)
backend.rollback_migrations(migrations, args.force)
migrations = backend.to_apply(migrations)
backend.apply_migrations(migrations, args.force)
+ return 0
-def rollback(args, config):
+def rollback(args, config) -> int:
backend = get_backend(args, config)
with backend.lock():
migrations = get_migrations(args, backend)
backend.rollback_migrations(migrations, args.force)
+ return 0
-def develop(args, config):
+def develop(args, config) -> int:
args.batch_mode = True
backend = get_backend(args, config)
with backend.lock():
@@ -303,28 +306,32 @@ def develop(args, config):
backend.rollback_migrations(migrations, args.force)
migrations = get_migrations(args, backend, "apply")
backend.apply_migrations(migrations, args.force)
+ return 0
-def mark(args, config):
+def mark(args, config) -> int:
backend = get_backend(args, config)
with backend.lock():
migrations = get_migrations(args, backend)
backend.mark_migrations(migrations)
+ return 0
-def unmark(args, config):
+def unmark(args, config) -> int:
backend = get_backend(args, config)
with backend.lock():
migrations = get_migrations(args, backend)
backend.unmark_migrations(migrations)
+ return 0
-def break_lock(args, config):
+def break_lock(args, config) -> int:
backend = get_backend(args, config)
backend.break_lock()
+ return 0
-def list_migrations(args, config):
+def list_migrations(args, config) -> int:
backend = get_backend(args, config)
migrations = read_migrations(*args.sources)
migrations = filter_migrations(migrations, args.match)
@@ -343,6 +350,7 @@ def list_migrations(args, config):
for m in migrations
)
print(tabulate.tabulate(data, headers=("STATUS", "ID", "SOURCE")))
+ return 0
def prompt_migrations(backend, migrations, direction):
diff --git a/yoyo/scripts/newmigration.py b/yoyo/scripts/newmigration.py
index 0629441..13b2986 100644
--- a/yoyo/scripts/newmigration.py
+++ b/yoyo/scripts/newmigration.py
@@ -89,7 +89,7 @@ def install_argparsers(global_parser, subparsers):
)
-def new_migration(args, config):
+def new_migration(args, config) -> int:
try:
directory = args.sources[0]
@@ -115,7 +115,7 @@ def new_migration(args, config):
else:
p = create_with_editor(config, directory, migration_source, extension)
if p is None:
- return
+ return 1
try:
command = config.get("DEFAULT", CONFIG_NEW_MIGRATION_COMMAND_KEY)
@@ -126,6 +126,7 @@ def new_migration(args, config):
pass
print("Created file", p)
+ return 0
def slugify(message):