1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use super::Parser;
use crate::parsers::entity_selector::EntitySelector;
use crate::parsers::{CommandArg, CommandArgParseError, ParseInput};

#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum ScoreHolder {
    Entity(EntitySelector),
    #[default]
    All,
}

impl CommandArg for ScoreHolder {
    fn parse_arg(input: &mut ParseInput) -> Result<Self, CommandArgParseError> {
        input.skip_whitespace();
        if input.peek() == Some('*') {
            Ok(ScoreHolder::All)
        } else {
            Ok(ScoreHolder::Entity(EntitySelector::parse_arg(input)?))
        }
    }

    fn display() -> Parser {
        Parser::ScoreHolder {
            allow_multiple: false,
        }
    }
}