feat: Add comments to generated files

This commit is contained in:
Ginger 2026-01-12 10:03:13 -05:00
parent 66fcedf08b
commit 7b159bc8c8
No known key found for this signature in database
12 changed files with 33 additions and 2 deletions

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin appservices`
- Commands for managing appservices

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin check`
- Commands for checking integrity

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin debug`
- Commands for debugging things

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin federation`
- Commands for managing federation

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# Admin Commands
These are all the admin commands. TODO fill me out

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin media`
- Commands for managing media

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin query`
- Low-level queries for database getters and iterators

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin rooms`
- Commands for managing rooms

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin server`
- Commands for managing the server

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin token`
- Commands for managing registration tokens

View file

@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin users`
- Commands for managing local users

View file

@ -1,6 +1,6 @@
mod admin_commands;
use std::{collections::HashMap, path::{Path, PathBuf}};
use std::{collections::HashMap, fs::File, io::Write, path::{Path, PathBuf}};
use cargo_metadata::MetadataCommand;
@ -16,13 +16,33 @@ struct FileQueue {
}
impl FileQueue {
const GENERATED_HEADER: &'static str = "This file is generated by `cargo xtask generate-docs`. Do not edit.";
/// Generate the header for the file at `path`.
fn header_for(path: &Path) -> Option<String> {
Some(match path.extension()?.as_encoded_bytes() {
b"md" => format!("<!-- {} -->", Self::GENERATED_HEADER),
_ => return None
})
}
/// Write all queued files into the file tree rooted at `root`.
fn write(self, root: &Path, dry_run: bool) -> std::io::Result<()> {
for (path, contents) in self.queue {
let path = root.join(&path);
eprintln!("Writing {}", path.display());
if !dry_run {
std::fs::write(path, contents)?;
let mut file = File::create(&path)?;
if let Some(header) = Self::header_for(&path) {
writeln!(file, "{header}")?;
}
write!(file, "{contents}")?;
if !contents.ends_with('\n') {
writeln!(file)?;
}
}
}