aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index acb08ad..44dab99 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -21,13 +21,13 @@ struct Config {
21 #[clap(short, long)] 21 #[clap(short, long)]
22 list: bool, 22 list: bool,
23 /// Maximum substitution depth 23 /// Maximum substitution depth
24 #[clap(short, long, default_value_t = 10, value_name = "N")] 24 #[clap(short, long, default_value_t=10, value_name="N")]
25 depth: u32, 25 depth: u32,
26 /// Base output directory [default: './'] 26 /// Base output directory [default: './']
27 #[clap(short, long, value_name = "PATH")] 27 #[clap(short, long, value_name="PATH")]
28 output: Option<PathBuf>, 28 output: Option<PathBuf>,
29 /// Limit entry points to those matching the provided prefix 29 /// Limit entry points to those matching the given prefix
30 #[clap(short, long, value_name = "PREFIX")] 30 #[clap(short, long, value_name="PREFIX")]
31 target: Option<PathBuf>, 31 target: Option<PathBuf>,
32 /// Input files 32 /// Input files
33 input: Vec<PathBuf>, 33 input: Vec<PathBuf>,
@@ -63,7 +63,9 @@ fn build(
63 } 63 }
64 blocks 64 blocks
65 .iter() 65 .iter()
66 .filter_map(|(key,code)| { key.get_path().map(|k| (k,code)) }) 66 .filter_map(|(key,code)| {
67 key.get_path().map(|k| (k,code))
68 })
67 .for_each(|(path,code)| { 69 .for_each(|(path,code)| {
68 let mut current_depth = 0; 70 let mut current_depth = 0;
69 let mut code = code.clone(); 71 let mut code = code.clone();
@@ -73,7 +75,9 @@ fn build(
73 if current_depth < max_depth { 75 if current_depth < max_depth {
74 let block = blocks 76 let block = blocks
75 .get(&Key::Macro(caps[2].to_string())) 77 .get(&Key::Macro(caps[2].to_string()))
76 .unwrap_or_else(|| panic!("Block \"{}\" not present", caps[2].to_string())) 78 .unwrap_or_else(|| panic!(
79 "Block \"{}\" not present",
80 caps[2].to_string()))
77 .clone(); 81 .clone();
78 indent(block, caps[1].len()) 82 indent(block, caps[1].len())
79 } else { 83 } else {
@@ -125,7 +129,10 @@ fn write_to_file(
125 fs::create_dir_all(path.parent().unwrap())?; 129 fs::create_dir_all(path.parent().unwrap())?;
126 fs::write(path, content)?; 130 fs::write(path, content)?;
127 } else { 131 } else {
128 eprintln!("Absolute paths not supported: {}", path.display()) 132 eprintln!(
133 "Absolute paths not supported: {}",
134 path.display()
135 )
129 } 136 }
130 Ok(()) 137 Ok(())
131} 138}
@@ -156,9 +163,11 @@ fn main() -> Result<()> {
156 let entry = clss.contains(&String::from("entry")); 163 let entry = clss.contains(&String::from("entry"));
157 let path = attrs 164 let path = attrs
158 .into_iter() 165 .into_iter()
159 .find_map(|(k,p)| if k == "path" { Some(p.clone()) } else { None }); 166 .find_map(|(k,p)|
167 if k == "path" { Some(p.clone()) } else { None });
160 if entry || path.is_some() || PATH.is_match(id) { 168 if entry || path.is_some() || PATH.is_match(id) {
161 let path = PathBuf::from(path.unwrap_or_default()).join(id); 169 let path =
170 PathBuf::from(path.unwrap_or_default()).join(id);
162 if path.starts_with(&target) { 171 if path.starts_with(&target) {
163 Some(Key::Entry(path)) 172 Some(Key::Entry(path))
164 } else { 173 } else {