diff --git a/src/main.rs b/src/main.rs index 4993f8b..dd35a18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ struct Options { description_extract: bool, /// Extract the description of the function category from the given markdown file. - #[arg(long)] + #[arg(long)] description_file: Option, /// Nix file to process. @@ -370,15 +370,24 @@ fn collect_entries(root: rnix::Root, category: &str) -> Vec { vec![] } -fn retrieve_description(nix: &rnix::Root, description: &str, description_extract: bool, description_file: Option, category: &str) -> String { +fn retrieve_description( + nix: &rnix::Root, + description: &str, + description_extract: bool, + description_file: Option, + category: &str, +) -> String { if description_extract { - dedent(&nix.syntax() - .first_child() - .and_then(|node| retrieve_doc_comment(&node, true)) - .expect("could not read description from top-level comment")) + dedent( + &nix.syntax() + .first_child() + .and_then(|node| retrieve_doc_comment(&node, true)) + .expect("could not read description from top-level comment"), + ) } else if let Some(filename) = description_file { - let content = fs::read_to_string(&filename) - .unwrap_or_else(|e| panic!("could not read description from \"{:?}\": {}", filename, e)); + let content = fs::read_to_string(&filename).unwrap_or_else(|e| { + panic!("could not read description from \"{:?}\": {}", filename, e) + }); dedent(&content) } else { format!( @@ -400,7 +409,13 @@ fn main() { .expect("could not read location information"), }; let nix = rnix::Root::parse(&src).ok().expect("failed to parse input"); - let description = retrieve_description(&nix, &opts.description, opts.description_extract, opts.description_file, &opts.category); + let description = retrieve_description( + &nix, + &opts.description, + opts.description_extract, + opts.description_file, + &opts.category, + ); // TODO: move this to commonmark.rs writeln!(output, "{}", description).expect("Failed to write header"); @@ -446,7 +461,13 @@ fn test_description_in_external_file() { let src = fs::read_to_string("test/line-comments.nix").unwrap(); let nix = rnix::Root::parse(&src).ok().expect("failed to parse input"); let category = "line-comments"; - let desc = retrieve_description(&nix, &"", false, Some("test/line-comments.md".into()), category); + let desc = retrieve_description( + &nix, + &"", + false, + Some("test/line-comments.md".into()), + category, + ); writeln!(output, "{}", desc).expect("Failed to write header"); for entry in collect_entries(nix, category) {