aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2022-12-30 16:14:19 +0000
committerFederico Igne <git@federicoigne.com>2022-12-30 16:14:19 +0000
commitd27d5e9094f0f5916266e0460ff0877ef330bd2d (patch)
tree5b81f15572b12f6291ad833f5f80bd68b1b574ea
parent481b08d9297e16e7c8eb29defc1a8b3302b937e5 (diff)
downloadpangler-d27d5e9094f0f5916266e0460ff0877ef330bd2d.tar.gz
pangler-d27d5e9094f0f5916266e0460ff0877ef330bd2d.zip
feat(list): add flag to list valid entry points
-rw-r--r--README.md36
-rw-r--r--src/main.rs25
2 files changed, 43 insertions, 18 deletions
diff --git a/README.md b/README.md
index 94f4a43..a5979ee 100644
--- a/README.md
+++ b/README.md
@@ -236,6 +236,7 @@ The `struct` holding the CLI information is defined as follow
236#[derive(Parser, Debug)] 236#[derive(Parser, Debug)]
237#[clap(author, version, about, long_about = None)] 237#[clap(author, version, about, long_about = None)]
238struct Config { 238struct Config {
239 <<config_list>>
239 <<config_depth>> 240 <<config_depth>>
240 <<config_output>> 241 <<config_output>>
241 <<config_target>> 242 <<config_target>>
@@ -265,8 +266,8 @@ By default `pangler` will generate all entry points gathered from the input file
265This behaviour can be overridden with the `-t/--target` flag. 266This behaviour can be overridden with the `-t/--target` flag.
266 267
267```{#config_target .rust} 268```{#config_target .rust}
268/// Target files prefix 269/// Limit entry points to those matching the provided prefix
269#[clap(short, long)] 270#[clap(short, long, value_name = "PREFIX")]
270target: Option<PathBuf>, 271target: Option<PathBuf>,
271``` 272```
272 273
@@ -276,6 +277,18 @@ let target = config.target.unwrap_or_default();
276 277
277Any entry point that does not have the provided target *as a prefix* will be ignored. 278Any entry point that does not have the provided target *as a prefix* will be ignored.
278 279
280## Listing entry points
281
282Sometimes it might be useful to simply get a list of all entry points considered by `pangler` for a specific input.
283Using the `-l/--list` flag, `pangler` will simply list all valid entry points to stdout and exit.
284Note that the output will be consistent with any provided [target](#specifying-target-entry-points).
285
286```{#config_list .rust}
287/// Simply list entry points and exit
288#[clap(short, long)]
289list: bool,
290```
291
279## Custom output folder 292## Custom output folder
280 293
281By default, files are generated in the current working directory. 294By default, files are generated in the current working directory.
@@ -289,7 +302,7 @@ If the output folder does not exists, *it will be created*.
289 302
290```{#config_output .rust} 303```{#config_output .rust}
291/// Base output directory [default: './'] 304/// Base output directory [default: './']
292#[clap(short, long)] 305#[clap(short, long, value_name = "PATH")]
293output: Option<PathBuf>, 306output: Option<PathBuf>,
294``` 307```
295 308
@@ -300,7 +313,7 @@ By default, `pangler` will stop after 10 substitution iterations, but this param
300 313
301```{#config_depth .rust} 314```{#config_depth .rust}
302/// Maximum substitution depth 315/// Maximum substitution depth
303#[clap(short, long, default_value_t = 10)] 316#[clap(short, long, default_value_t = 10, value_name = "N")]
304depth: u32, 317depth: u32,
305``` 318```
306 319
@@ -405,9 +418,17 @@ pandoc.blocks.iter().for_each(|block|
405``` 418```
406 419
407And then we build the source code, making sure to cut off recursive code generation with depth larger than `config.depth`. 420And then we build the source code, making sure to cut off recursive code generation with depth larger than `config.depth`.
421If the `-l/--list` flag is provided, `pangler` will simply list the available entry points and exit.
408 422
409```{#pandoc_filter .rust} 423```{#pandoc_filter .rust}
410build(&config.output, &blocks, config.depth); 424if config.list {
425 blocks.keys().for_each(|k| match k {
426 Key::Entry(s) => println!("{}", s.display()),
427 Key::Macro(_) => {}
428 });
429} else {
430 build(&config.output, &blocks, config.depth);
431}
411``` 432```
412 433
413The filter returns the Pandoc JSON unchanged. 434The filter returns the Pandoc JSON unchanged.
@@ -626,10 +647,7 @@ fn write_to_file(
626 <<parent_directory_creation>> 647 <<parent_directory_creation>>
627 <<write_to_file>> 648 <<write_to_file>>
628 } else { 649 } else {
629 eprintln!( 650 eprintln!("Absolute paths not supported: {}", path.display())
630 "Absolute paths not supported: {}",
631 path.to_string_lossy()
632 )
633 } 651 }
634 Ok(()) 652 Ok(())
635} 653}
diff --git a/src/main.rs b/src/main.rs
index 1d6bdd4..acb08ad 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,14 +17,17 @@ const BASE: &str = "./";
17#[derive(Parser, Debug)] 17#[derive(Parser, Debug)]
18#[clap(author, version, about, long_about = None)] 18#[clap(author, version, about, long_about = None)]
19struct Config { 19struct Config {
20 /// Simply list entry points and exit
21 #[clap(short, long)]
22 list: bool,
20 /// Maximum substitution depth 23 /// Maximum substitution depth
21 #[clap(short, long, default_value_t = 10)] 24 #[clap(short, long, default_value_t = 10, value_name = "N")]
22 depth: u32, 25 depth: u32,
23 /// Base output directory [default: './'] 26 /// Base output directory [default: './']
24 #[clap(short, long)] 27 #[clap(short, long, value_name = "PATH")]
25 output: Option<PathBuf>, 28 output: Option<PathBuf>,
26 /// Target files prefix 29 /// Limit entry points to those matching the provided prefix
27 #[clap(short, long)] 30 #[clap(short, long, value_name = "PREFIX")]
28 target: Option<PathBuf>, 31 target: Option<PathBuf>,
29 /// Input files 32 /// Input files
30 input: Vec<PathBuf>, 33 input: Vec<PathBuf>,
@@ -122,10 +125,7 @@ fn write_to_file(
122 fs::create_dir_all(path.parent().unwrap())?; 125 fs::create_dir_all(path.parent().unwrap())?;
123 fs::write(path, content)?; 126 fs::write(path, content)?;
124 } else { 127 } else {
125 eprintln!( 128 eprintln!("Absolute paths not supported: {}", path.display())
126 "Absolute paths not supported: {}",
127 path.to_string_lossy()
128 )
129 } 129 }
130 Ok(()) 130 Ok(())
131} 131}
@@ -186,7 +186,14 @@ fn main() -> Result<()> {
186 } 186 }
187 } 187 }
188 ); 188 );
189 build(&config.output, &blocks, config.depth); 189 if config.list {
190 blocks.keys().for_each(|k| match k {
191 Key::Entry(s) => println!("{}", s.display()),
192 Key::Macro(_) => {}
193 });
194 } else {
195 build(&config.output, &blocks, config.depth);
196 }
190 pandoc 197 pandoc
191 } 198 }
192 ) 199 )