-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirection.rs
More file actions
24 lines (23 loc) · 847 Bytes
/
Copy pathredirection.rs
File metadata and controls
24 lines (23 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pub enum Redirection<'a> {
RedirectStdout(&'a str),
RedirectStderr(&'a str),
AppendStdout(&'a str),
AppendStderr(&'a str),
}
impl<'a> Redirection<'a> {
pub(crate) fn extract(args: &'a [String]) -> (&'a [String], Option<Self>) {
match args {
[head @ .., arg, path] if arg == ">" || arg == "1>" => {
(head, Some(Redirection::RedirectStdout(path)))
}
[head @ .., arg, path] if arg == ">>" || arg == "1>>" => {
(head, Some(Redirection::AppendStdout(path)))
}
[head @ .., arg, path] if arg == "2>" => {
(head, Some(Redirection::RedirectStderr(path)))
}
[head @ .., arg, path] if arg == "2>>" => (head, Some(Redirection::AppendStderr(path))),
_ => (args, None),
}
}
}