1
use crate::commands::{
2
    Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
3
    ResponseParserError,
4
};
5

            
6
pub struct PlaylistMove;
7

            
8
impl Command for PlaylistMove {
9
    type Response = ();
10
    const COMMAND: &'static str = "playlistmove";
11

            
12
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
13
        let playlist_name = parts
14
            .next()
15
            .ok_or(RequestParserError::UnexpectedEOF)?
16
            .to_string();
17

            
18
        let mut from = None;
19
        let from_or_range_or_to = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
20

            
21
        let to = parts.next();
22

            
23
        debug_assert!(parts.next().is_none());
24

            
25
        let to = if let Some(to) = to {
26
            from = Some(from_or_range_or_to.parse().map_err(|_| {
27
                RequestParserError::SyntaxError(0, from_or_range_or_to.to_string())
28
            })?);
29
            to.parse()
30
                .map_err(|_| RequestParserError::SyntaxError(0, to.to_string()))?
31
        } else {
32
            from_or_range_or_to
33
                .parse()
34
                .map_err(|_| RequestParserError::SyntaxError(0, from_or_range_or_to.to_string()))?
35
        };
36

            
37
        Ok((Request::PlaylistMove(playlist_name, from, to), ""))
38
    }
39

            
40
    fn parse_response(
41
        parts: ResponseAttributes<'_>,
42
    ) -> Result<Self::Response, ResponseParserError> {
43
        debug_assert!(parts.is_empty());
44
        Ok(())
45
    }
46
}