-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathtransfer.rs
38 lines (32 loc) · 1004 Bytes
/
transfer.rs
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
30
31
32
33
34
35
36
37
38
//! Parses the `@bot transfer reponame` command.
use crate::error::Error;
use crate::token::{Token, Tokenizer};
use std::fmt;
#[derive(Debug, PartialEq, Eq)]
pub struct TransferCommand(pub String);
#[derive(Debug)]
pub enum ParseError {
MissingRepo,
}
impl std::error::Error for ParseError {}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::MissingRepo => write!(f, "missing repository name"),
}
}
}
impl TransferCommand {
pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result<Option<Self>, Error<'a>> {
if !matches!(input.peek_token()?, Some(Token::Word("transfer"))) {
return Ok(None);
}
input.next_token()?;
let repo = if let Some(Token::Word(repo)) = input.next_token()? {
repo.to_owned()
} else {
return Err(input.error(ParseError::MissingRepo));
};
Ok(Some(TransferCommand(repo)))
}
}