diff --git a/src/chap/core.py b/src/chap/core.py index 00c81d1..665d682 100644 --- a/src/chap/core.py +++ b/src/chap/core.py @@ -177,12 +177,23 @@ def colonstr(arg: str) -> tuple[str, str]: def set_system_message(ctx: click.Context, param: click.Parameter, value: str) -> None: - if value and value.startswith("@"): + if value is None: + return + if value.startswith("@"): with open(value[1:], "r", encoding="utf-8") as f: - value = f.read().rstrip() + value = f.read().strip() ctx.obj.system_message = value +def set_system_message_from_file( + ctx: click.Context, param: click.Parameter, value: click.File +) -> None: + if value is None: + return + content = value.read().strip() + ctx.obj.system_message = content + + def set_backend(ctx: click.Context, param: click.Parameter, value: str) -> None: if value == "list": formatter = ctx.make_formatter() @@ -369,6 +380,13 @@ def format_options( help="Show the version and exit", callback=version_callback, ), + click.Option( + ("--system-message-file", "-@"), + type=click.File("r"), + default=None, + callback=set_system_message_from_file, + expose_value=False, + ), click.Option( ("--system-message", "-S"), type=str,