1 | use crate::Result; |
2 | |
3 | pub fn expand<I, S>(args: I) -> Result<Vec<String>> |
4 | where |
5 | I: IntoIterator<Item = S>, |
6 | S: AsRef<str>, |
7 | { |
8 | let mut result: Vec = vec![]; |
9 | from_iter(&mut result, args)?; |
10 | Ok(result) |
11 | } |
12 | |
13 | fn from_string(result: &mut Vec<String>, value: &str) -> Result<()> { |
14 | let value: &str = if let Some((value: &str, _)) = value.split_once(delimiter:'#' ) { value } else { value }; |
15 | |
16 | from_iter(result, args:value.split_whitespace().map(|arg: &str| arg.to_string()))?; |
17 | Ok(()) |
18 | } |
19 | |
20 | fn from_iter<I, S>(result: &mut Vec<String>, args: I) -> Result<()> |
21 | where |
22 | I: IntoIterator<Item = S>, |
23 | S: AsRef<str>, |
24 | { |
25 | let mut expand: bool = false; |
26 | |
27 | for arg: String in args.into_iter().map(|arg: S| arg.as_ref().to_string()) { |
28 | if arg.starts_with('-' ) { |
29 | expand = false; |
30 | } |
31 | if expand { |
32 | for args: String in crate::read_file_lines(&arg)? { |
33 | if !args.starts_with("//" ) { |
34 | from_string(result, &args)?; |
35 | } |
36 | } |
37 | } else if arg == "--etc" { |
38 | expand = true; |
39 | } else { |
40 | result.push(arg); |
41 | } |
42 | } |
43 | |
44 | Ok(()) |
45 | } |
46 | |