/// What mode does this argument change to, if any?
fnmode_change_kind(&self)-> Option<ModeKind>
{
Some(matchself
{
Self::ModeChangeHelp=>ModeKind::Help,
_=>returnNone,
})
}
/// Convert into a mode change if this is a mode change
// We consume the whole output here in case the mode change needs to traverse it for information. As of now, we have only one non-`Normal` mode: `Help`, which doesn't require any extra information.
#[deprecated(note = "mode selection happens in `into_mode` and early return through `Continue::Abort` will be removed or reworked to not require this function.")]
/// Returning this when the contained value is `Some` immediately terminates parsing and precedes to mode-switch. However, if it is `None`, parsing of chained short args is allowed to continue, although `Abort(None)` will be returned at the end regardless of subsequent `Continue` results from that change (unless one is an `Abort(Some(_))`, which immediately returns itself.)
// Box `Argument` to reduce the size of `Continue`, as it is returned from functions often and when its value is set to `Some` it will always be the last `Argument` processed anyway and the only one to be boxed here at all.
//TODO: Deprecate the early return of an `Argument` here. Either change it to `Mode`, or have no early return. Mode change happens at the bottom in `into_mode` now.
Abort(Option<Box<Argument>>),
}
@ -416,9 +451,21 @@ mod modes {
/// Consume this parsed list of arguments into a `Mode` and return it
pubfninto_mode(args: Output)-> eyre::Result<Mode>
{
//TODO: Find out what mode `args` is in.
//TODO: pass `args` to the respective mode generation function in mode `modes`, and wrap that mode around its return value.
letmutmode_kind=ModeKind::default();//Normal.
forarginargs.iter(){
//find any mode change Argument (with `Argument::mode_change_kind()`) in `args`, changing `mode_kind` in turn. There should be at most 1.
ifletSome(mode)=arg.mode_change_kind()
{
mode_kind=mode;
break;
}
}
//pass `args` to the respective mode generation function in mode `modes`, and wrap that mode around its return value.