Skip to content
Closed
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
17 changes: 16 additions & 1 deletion src/google/adk/cli/cli_tools_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ class HelpfulCommand(click.Command):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@staticmethod
def _format_missing_arg_error(click_exception):
"""Format the missing argument error with uppercase parameter name.

Args:
click_exception: The MissingParameter exception from Click.

Returns:
str: Formatted error message with uppercase parameter name.
"""
name = click_exception.param.name
return f"Missing required argument: {name.upper()}"

def parse_args(self, ctx, args):
"""Override the parse_args method to show help text on error.
Expand All @@ -77,8 +90,10 @@ def parse_args(self, ctx, args):
try:
return super().parse_args(ctx, args)
except click.MissingParameter as exc:
error_message = self._format_missing_arg_error(exc)

click.echo(ctx.get_help())
click.secho(f"\nError: {str(exc)}", fg="red", err=True)
click.secho(f"\nError: {error_message}", fg="red", err=True)
ctx.exit(2)


Expand Down