-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathentry.rs
More file actions
79 lines (68 loc) · 1.51 KB
/
entry.rs
File metadata and controls
79 lines (68 loc) · 1.51 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//^
//^ HEAD
//^
//> HEAD -> PRELUDE
use crate::prelude::{
FilePath,
readFile,
writeFile,
EnumString,
AsRefStr
};
//> HEAD -> LOCAL
use super::issues::Issue;
//^
//^ ARGUMENT
//^
//> ARGUMENT -> ENUM
pub enum Argument {
File(File),
Flag(Flag),
Alias(Alias),
Target(Target)
}
//^
//^ INPUT
//^
//> INPUT -> FILE
#[derive(Clone)]
pub struct File (pub FilePath); impl File {
pub fn read(&self) -> Result<String, Issue> {readFile(&self.0).ok().ok_or_else(|| Issue::FileNotFound(self.0.to_str().unwrap().to_string()))}
pub fn write(&self, extension: &str, content: String) -> () {
let mut path = self.0.clone();
path.set_extension(extension);
writeFile(path, content).unwrap();
}
}
//> INPUT -> FLAG
#[derive(EnumString, Clone, Copy, AsRefStr)]
#[strum(serialize_all = "lowercase")]
pub enum Flag {
Quiet,
Verbose
}
//> INPUT -> ALIAS
#[derive(Clone, Debug)]
pub struct Alias(pub Vec<char>); impl Alias {pub fn expand(self) -> Result<Vec<Flag>, Issue> {
let mut converted = Vec::new();
for letter in &self.0 {converted.push(match letter {
'q' => Flag::Quiet,
'v' => Flag::Verbose,
other => return Err(Issue::UnknownAliasCharacter {
alias: self,
at: converted.len()
})
})}
return Ok(converted);
}}
//> INPUT -> TARGET
#[derive(EnumString, Clone, AsRefStr, Copy)]
#[strum(serialize_all = "lowercase")]
pub enum Target {
Help,
Version,
Tokens,
Check,
Ast,
Latex
}