Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions src/mail/protocol/src/mail_protocol/cli_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@
CommandHelp = tuple[str, str]
CommandGroup = tuple[str, Sequence[CommandHelp]]

LICENSE_NOTICE = """\
MAIL - Multi-Agent Interface Layer
Copyright (c) 2025-present MAIL Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the LICENSE and NOTICE files
distributed with this project for the full terms."""


class _LicenseAction(argparse.Action):
"""Print MAIL's license notice and exit, mirroring argparse's --version."""

def __init__(
self,
option_strings: Sequence[str],
dest: str = argparse.SUPPRESS,
default: str = argparse.SUPPRESS,
help: str = "show license information and exit",
):
super().__init__(
option_strings=option_strings,
dest=dest,
default=default,
nargs=0,
help=help,
)

def __call__(self, parser, namespace, values, option_string=None):
parser.exit(message=LICENSE_NOTICE + "\n")


class MAILHelpFormatter(
argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -24,7 +60,7 @@ def build_epilog(
*,
command_groups: Sequence[CommandGroup] | None = None,
examples: Sequence[str] | None = None,
footer: str | None = "Copyright (c) 2026 Addison Kline",
footer: str | None = "Copyright (c) 2025-present MAIL Contributors",
) -> str | None:
sections: list[str] = []

Expand All @@ -51,6 +87,11 @@ def build_epilog(
return "\n\n".join(sections)


def add_license_argument(parser: argparse.ArgumentParser) -> None:
"""Add a `--license` flag that prints MAIL's license notice and exits."""
parser.add_argument("--license", action=_LicenseAction)


def make_arg_parser(
*,
prog: str,
Expand All @@ -59,13 +100,15 @@ def make_arg_parser(
command_groups: Sequence[CommandGroup] | None = None,
examples: Sequence[str] | None = None,
) -> argparse.ArgumentParser:
return argparse.ArgumentParser(
parser = argparse.ArgumentParser(
prog=prog,
usage=usage,
description=description,
epilog=build_epilog(command_groups=command_groups, examples=examples),
formatter_class=MAILHelpFormatter,
)
add_license_argument(parser)
return parser


def add_hidden_subparsers(parser: argparse.ArgumentParser):
Expand Down
4 changes: 3 additions & 1 deletion src/mail/server/src/mail_server/backend_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse

from mail_protocol.cli_help import add_license_argument
from mail_protocol.core.validators import (
validate_agent_names,
validate_daemon_worker_names,
Expand All @@ -21,8 +22,9 @@ def main() -> None:
prog="backend-init",
usage="backend-init [option]...",
description="Initialize the MAIL server backend for use by mail-server",
epilog="Copyright (c) 2026 Addison Kline",
epilog="Copyright (c) 2025-present MAIL Contributors",
)
add_license_argument(parser)
parser.add_argument(
"-t",
"--type",
Expand Down
Loading