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
28
29
use super::Parser;
use crate::parsers::{CommandArg, CommandArgParseError, ParseInput};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum EntityAnchor {
    #[default]
    Eyes,
    Feet,
}

impl CommandArg for EntityAnchor {
    fn parse_arg(input: &mut ParseInput) -> Result<Self, CommandArgParseError> {
        input.skip_whitespace();
        if input.match_next("eyes") {
            Ok(EntityAnchor::Eyes)
        } else if input.match_next("feet") {
            Ok(EntityAnchor::Feet)
        } else {
            Err(CommandArgParseError::InvalidArgument {
                expected: "entity_anchor".to_owned(),
                got: "not a valid entity anchor".to_owned(),
            })
        }
    }

    fn display() -> Parser {
        Parser::EntityAnchor
    }
}