Skip to content

Commit 058adb2

Browse files
committed
✨ use Custom missing tips for outer handler
1 parent 36bd5ba commit 058adb2

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

example/endpoint.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class User:
88
name: str
99
age: int
1010

11+
1112
user_ = Alconna(
1213
"user",
1314
Option("list"),
@@ -26,6 +27,7 @@ class User:
2627

2728
users = {}
2829

30+
2931
def handle(send: str):
3032
res = user_.parse(send)
3133
if not res.matched:

src/arclet/alconna/_internal/_analyser.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ def analyse(self, argv: Argv[TDC]) -> Self:
226226
if self.default_main_only and not self.args_result:
227227
self.args_result = analyse_args(argv, self.self_args)
228228
if not self.args_result and self.need_main_args:
229-
raise ArgumentMissing(lang.require("subcommand", "args_missing").format(name=self.command.dest))
229+
raise ArgumentMissing(
230+
self.self_args.argument[0].field.get_missing_tips(
231+
lang.require("subcommand", "args_missing").format(name=self.command.dest)
232+
)
233+
)
230234
return self
231235

232236
def get_sub_analyser(self, target: Subcommand) -> SubAnalyser[TDC] | None:
@@ -384,7 +388,9 @@ def process(self, argv: Argv[TDC]) -> Arparma[TDC]:
384388
return handle_completion(self, argv, rest[-2])
385389
exc = ParamsUnmatched(lang.require("analyser", "param_unmatched").format(target=argv.next(move=False)[0]))
386390
else:
387-
exc = ArgumentMissing(lang.require("analyser", "param_missing"))
391+
exc = ArgumentMissing(
392+
self.self_args.argument[0].field.get_missing_tips(lang.require("analyser", "param_missing"))
393+
)
388394
if comp_ctx.get(None) and isinstance(exc, ArgumentMissing):
389395
raise PauseTriggered(prompt(self, argv), exc, argv)
390396
if self.command.meta.raise_exception:

0 commit comments

Comments
 (0)