mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-14 09:51:25 -06:00
fix: Display full help text for adk create CLI command when argument…
Copybara import of the project: -- dcfb9ff720562802f9ce15c90a71b4cd40f77280 by Eugen-Bleck <eugenbleck@gmail.com>: fix: Display full help text for adk create CLI command when arguments are missing -- f2eea8d1e5947b1631ac2de3824d8bf0cf833cbc by Eugen-Bleck <eugenbleck@gmail.com>: fix: Display full help text for adk run and eval CLI command when arguments are missing COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/443 from bl3ck:fix/cli-help-display c2bca420b00aa3391ab8cfb6baedc9ea0dbfb7e1 PiperOrigin-RevId: 758498242
This commit is contained in:
parent
fc40226ec0
commit
b33bdb9a03
@ -34,6 +34,50 @@ from .fast_api import get_fast_api_app
|
|||||||
from .utils import envs
|
from .utils import envs
|
||||||
from .utils import logs
|
from .utils import logs
|
||||||
|
|
||||||
|
|
||||||
|
class HelpfulCommand(click.Command):
|
||||||
|
"""Command that shows full help on error instead of just the error message.
|
||||||
|
|
||||||
|
A custom Click Command class that overrides the default error handling
|
||||||
|
behavior to display the full help text when a required argument is missing,
|
||||||
|
followed by the error message. This provides users with better context
|
||||||
|
about command usage without needing to run a separate --help command.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*args: Variable length argument list to pass to the parent class.
|
||||||
|
**kwargs: Arbitrary keyword arguments to pass to the parent class.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
None. Inherits behavior from the parent Click Command class.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def parse_args(self, ctx, args):
|
||||||
|
"""Override the parse_args method to show help text on error.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ctx: Click context object for the current command.
|
||||||
|
args: List of command-line arguments to parse.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The parsed arguments as returned by the parent class's parse_args method.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
click.MissingParameter: When a required parameter is missing, but this
|
||||||
|
is caught and handled by displaying the help text before exiting.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return super().parse_args(ctx, args)
|
||||||
|
except click.MissingParameter as exc:
|
||||||
|
click.echo(ctx.get_help())
|
||||||
|
click.secho(f"\nError: {str(exc)}", fg="red", err=True)
|
||||||
|
ctx.exit(2)
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -49,7 +93,7 @@ def deploy():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@main.command("create")
|
@main.command("create", cls=HelpfulCommand)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--model",
|
"--model",
|
||||||
type=str,
|
type=str,
|
||||||
@ -115,7 +159,7 @@ def validate_exclusive(ctx, param, value):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@main.command("run")
|
@main.command("run", cls=HelpfulCommand)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--save_session",
|
"--save_session",
|
||||||
type=bool,
|
type=bool,
|
||||||
@ -196,7 +240,7 @@ def cli_run(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@main.command("eval")
|
@main.command("eval", cls=HelpfulCommand)
|
||||||
@click.argument(
|
@click.argument(
|
||||||
"agent_module_file_path",
|
"agent_module_file_path",
|
||||||
type=click.Path(
|
type=click.Path(
|
||||||
|
Loading…
Reference in New Issue
Block a user