Skip to content

Commit

Permalink
sistana-stargazing: feat: loopflow exit reason to legecy alconna exce…
Browse files Browse the repository at this point in the history
…ptions
  • Loading branch information
GreyElaina committed Sep 25, 2024
1 parent dd9db0c commit 1f4acf3
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/arclet/alconna/_stargazing/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from arclet.alconna import Alconna, Arg, Args, Arparma, HeadResult, Option, OptionResult, Subcommand, SubcommandResult
from arclet.alconna.sistana import Analyzer, Fragment, LoopflowDescription, OptionPattern, Preset, SubcommandPattern, Track, Value
from arclet.alconna.sistana.model.fragment import _Fragment

from arclet.alconna.exceptions import ArgumentMissing, InvalidArgs, InvalidParam, ParamsUnmatched, UnexpectedElement, NullMessage

def _alc_args_to_fragments(args: Args) -> deque[_Fragment]:
alc_argument = args.argument
Expand Down Expand Up @@ -124,4 +124,44 @@ def into_sistana(alconna: Alconna | Subcommand | Option):
)


def reason_raise_alc_exception(reason: LoopflowDescription) -> None:
if reason == LoopflowDescription.completed:
return

if reason in {
LoopflowDescription.unsatisfied,
LoopflowDescription.previous_unsatisfied,
LoopflowDescription.switch_unsatisfied_option,
LoopflowDescription.unsatisfied_switch_subcommand,
}:
raise ParamsUnmatched(f"LoopflowDescription: {reason.value}")

if reason in {
LoopflowDescription.out_of_data_subcommand,
LoopflowDescription.out_of_data_option,
}:
raise ArgumentMissing(f"LoopflowDescription: {reason.value}")

if reason in {
LoopflowDescription.prefix_expect_str,
LoopflowDescription.header_expect_str,
}:
raise InvalidParam(f"LoopflowDescription: {reason.value}")

if reason in {
LoopflowDescription.prefix_mismatch,
LoopflowDescription.header_mismatch,
}:
raise InvalidArgs(f"LoopflowDescription: {reason.value}")

if reason == LoopflowDescription.unexpected_segment:
raise UnexpectedElement(f"LoopflowDescription: {reason.value}")

if reason == LoopflowDescription.option_duplicated_prohibited:
raise NullMessage(f"LoopflowDescription: {reason.value}")





def process_adapt(): ...

0 comments on commit 1f4acf3

Please sign in to comment.