aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-09-29 20:36:59 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-09-29 20:36:59 +0200
commita90d279ca27293efcb5dac244f4fdf3498d75529 (patch)
tree663359f39fcdaffa6dc7c76ab868c8a6896feccf
parent282366e11f9cdda54dbedeb673bb894d53ec9147 (diff)
downloadfietsboek-a90d279ca27293efcb5dac244f4fdf3498d75529.tar.gz
fietsboek-a90d279ca27293efcb5dac244f4fdf3498d75529.tar.bz2
fietsboek-a90d279ca27293efcb5dac244f4fdf3498d75529.zip
fietsupdater: use Context.fail to abort
This makes sure that the exit code is set properly
-rw-r--r--fietsboek/updater/cli.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/fietsboek/updater/cli.py b/fietsboek/updater/cli.py
index 6a59100..45655d4 100644
--- a/fietsboek/updater/cli.py
+++ b/fietsboek/updater/cli.py
@@ -54,7 +54,8 @@ def cli():
help="Skip the safety question and just run the update",
)
@click.argument("version", required=False)
-def update(config, version, force):
+@click.pass_context
+def update(ctx, config, version, force):
"""Run the update process.
Make sure to consult the documentation and ensure that you have a backup
@@ -66,16 +67,17 @@ def update(config, version, force):
updater = Updater(config)
updater.load()
if version and not updater.exists(version):
- click.secho("Revision not found", fg="red")
- return
+ ctx.fail(f"Version {version!r} not found")
+
version_str = ", ".join(updater.current_versions())
click.echo(f"Current version: {version_str}")
if not version:
heads = updater.heads()
if len(heads) != 1:
- click.secho("Ambiguous heads, please specify the version to update to", fg="red")
- return
+ ctx.fail("Ambiguous heads, please specify the version to update to")
+
version = heads[0]
+
click.echo(f"Selected version: {version}")
if not force:
user_confirm()
@@ -92,7 +94,8 @@ def update(config, version, force):
help="Skip the safety question and just run the downgrade",
)
@click.argument("version")
-def downgrade(config, version, force):
+@click.pass_context
+def downgrade(ctx, config, version, force):
"""Run the downgrade process.
Make sure to consult the documentation and ensure that you have a backup
@@ -103,8 +106,8 @@ def downgrade(config, version, force):
updater = Updater(config)
updater.load()
if version and not updater.exists(version):
- click.secho("Revision not found", fg="red")
- return
+ ctx.fail(f"Version {version!r} not found")
+
version_str = ", ".join(updater.current_versions())
click.echo(f"Current version: {version_str}")
click.echo(f"Downgrade to version {version}")