Skip to content

Commit 52f9d2e

Browse files
committed
Catch and print CLI errors
1 parent f489440 commit 52f9d2e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

opslib/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import click
99

1010
from .operations import apply, print_report
11+
from .results import OperationError
1112
from .state import run_gc
1213

1314
logger = logging.getLogger(__name__)
@@ -117,7 +118,12 @@ def gc(dry_run):
117118
def component_(ctx, path, args):
118119
target = lookup(component, path)
119120
target_cli = get_cli(target)
120-
target_cli(obj=ctx.obj, args=args)
121+
try:
122+
target_cli(obj=ctx.obj, args=args)
123+
except OperationError as error:
124+
click.secho(f"Error in {target!r} {' '.join(args)}", fg="red", err=True)
125+
error.result.print_output()
126+
sys.exit(1)
121127

122128
def register_apply_command(name, *decorators, **defaults):
123129
@click.option("--pdb", "use_pdb", is_flag=True)

0 commit comments

Comments
 (0)