diff options
| author | Federico Igne <git@federicoigne.com> | 2022-12-30 13:43:32 +0000 |
|---|---|---|
| committer | Federico Igne <git@federicoigne.com> | 2022-12-30 13:43:32 +0000 |
| commit | a39e120e3fa6723c7ad8c4d27afca79233947935 (patch) | |
| tree | dd86083453db4260e016457bdfd3b6ee4b57157b /src | |
| parent | 909876999eb1eb968f71e6f8b199689cfc68f711 (diff) | |
| download | pangler-a39e120e3fa6723c7ad8c4d27afca79233947935.tar.gz pangler-a39e120e3fa6723c7ad8c4d27afca79233947935.zip | |
feat(target): allow limiting the generated entrypoints
Introduces the `-t/--target` flag that can be used to provide a path.
Only entry points that have this path as a prefix will be generated.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index 7d2f786..8168ad8 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -23,6 +23,9 @@ struct Config { | |||
| 23 | /// Base output directory [default: './'] | 23 | /// Base output directory [default: './'] |
| 24 | #[clap(short, long)] | 24 | #[clap(short, long)] |
| 25 | output: Option<PathBuf>, | 25 | output: Option<PathBuf>, |
| 26 | /// Target files prefix | ||
| 27 | #[clap(short, long)] | ||
| 28 | target: Option<PathBuf>, | ||
| 26 | /// Input files | 29 | /// Input files |
| 27 | input: Vec<PathBuf>, | 30 | input: Vec<PathBuf>, |
| 28 | } | 31 | } |
| @@ -131,6 +134,7 @@ fn write_to_file( | |||
| 131 | 134 | ||
| 132 | fn main() -> Result<()> { | 135 | fn main() -> Result<()> { |
| 133 | let config = Config::parse(); | 136 | let config = Config::parse(); |
| 137 | let target = config.target.unwrap_or_default(); | ||
| 134 | let mut pandoc = Pandoc::new(); | 138 | let mut pandoc = Pandoc::new(); |
| 135 | pandoc.set_input(InputKind::Files(config.input)); | 139 | pandoc.set_input(InputKind::Files(config.input)); |
| 136 | pandoc.set_input_format(InputFormat::Markdown, vec![]); | 140 | pandoc.set_input_format(InputFormat::Markdown, vec![]); |
| @@ -155,20 +159,27 @@ fn main() -> Result<()> { | |||
| 155 | .into_iter() | 159 | .into_iter() |
| 156 | .find_map(|(k,p)| if k == "path" { Some(p.clone()) } else { None }); | 160 | .find_map(|(k,p)| if k == "path" { Some(p.clone()) } else { None }); |
| 157 | if entry || path.is_some() || PATH.is_match(id) { | 161 | if entry || path.is_some() || PATH.is_match(id) { |
| 158 | Key::Entry(PathBuf::from(path.unwrap_or_default()).join(id)) | 162 | let path = PathBuf::from(path.unwrap_or_default()).join(id); |
| 163 | if path.starts_with(&target) { | ||
| 164 | Some(Key::Entry(path)) | ||
| 165 | } else { | ||
| 166 | None | ||
| 167 | } | ||
| 159 | } else { | 168 | } else { |
| 160 | Key::Macro(id.to_string()) | 169 | Some(Key::Macro(id.to_string())) |
| 161 | } | 170 | } |
| 162 | }; | 171 | }; |
| 163 | if clss.iter().any(|c| c == "override") { | 172 | if let Some(key) = key { |
| 164 | blocks.insert(key, Cow::from(code)); | 173 | if clss.iter().any(|c| c == "override") { |
| 165 | } else { | 174 | blocks.insert(key, Cow::from(code)); |
| 166 | blocks.entry(key) | 175 | } else { |
| 167 | .and_modify(|s| { | 176 | blocks.entry(key) |
| 168 | *s += "\n"; | 177 | .and_modify(|s| { |
| 169 | *s += Cow::from(code) | 178 | *s += "\n"; |
| 170 | }) | 179 | *s += Cow::from(code) |
| 171 | .or_insert(Cow::from(code)); | 180 | }) |
| 181 | .or_insert(Cow::from(code)); | ||
| 182 | } | ||
| 172 | } | 183 | } |
| 173 | } else { | 184 | } else { |
| 174 | eprintln!("Ignoring code block without ID:"); | 185 | eprintln!("Ignoring code block without ID:"); |
| @@ -183,4 +194,4 @@ fn main() -> Result<()> { | |||
| 183 | ); | 194 | ); |
| 184 | pandoc.execute().unwrap(); | 195 | pandoc.execute().unwrap(); |
| 185 | Ok(()) | 196 | Ok(()) |
| 186 | } | 197 | } \ No newline at end of file |
