Skip to content

Commit

Permalink
fix: rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
phaer committed Sep 5, 2023
1 parent c32f19b commit ca92f93
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// Nix file to process.
Expand Down Expand Up @@ -370,15 +370,24 @@ fn collect_entries(root: rnix::Root, category: &str) -> Vec<ManualEntry> {
vec![]
}

fn retrieve_description(nix: &rnix::Root, description: &str, description_extract: bool, description_file: Option<PathBuf>, category: &str) -> String {
fn retrieve_description(
nix: &rnix::Root,
description: &str,
description_extract: bool,
description_file: Option<PathBuf>,
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!(
Expand All @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ca92f93

Please sign in to comment.