feat: Add comments to generated files

This commit is contained in:
Ginger
2026-01-12 10:36:37 -05:00
parent 66fcedf08b
commit 7b159bc8c8
12 changed files with 33 additions and 2 deletions
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin appservices` # `!admin appservices`
- Commands for managing appservices - Commands for managing appservices
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin check` # `!admin check`
- Commands for checking integrity - Commands for checking integrity
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin debug` # `!admin debug`
- Commands for debugging things - Commands for debugging things
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin federation` # `!admin federation`
- Commands for managing federation - Commands for managing federation
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# Admin Commands # Admin Commands
These are all the admin commands. TODO fill me out These are all the admin commands. TODO fill me out
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin media` # `!admin media`
- Commands for managing media - Commands for managing media
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin query` # `!admin query`
- Low-level queries for database getters and iterators - Low-level queries for database getters and iterators
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin rooms` # `!admin rooms`
- Commands for managing rooms - Commands for managing rooms
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin server` # `!admin server`
- Commands for managing the server - Commands for managing the server
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin token` # `!admin token`
- Commands for managing registration tokens - Commands for managing registration tokens
+1
View File
@@ -1,3 +1,4 @@
<!-- This file is generated by `cargo xtask generate-docs`. Do not edit. -->
# `!admin users` # `!admin users`
- Commands for managing local users - Commands for managing local users
+22 -2
View File
@@ -1,6 +1,6 @@
mod admin_commands; 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; use cargo_metadata::MetadataCommand;
@@ -16,13 +16,33 @@ struct FileQueue {
} }
impl 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<()> { fn write(self, root: &Path, dry_run: bool) -> std::io::Result<()> {
for (path, contents) in self.queue { for (path, contents) in self.queue {
let path = root.join(&path); let path = root.join(&path);
eprintln!("Writing {}", path.display()); eprintln!("Writing {}", path.display());
if !dry_run { 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)?;
}
} }
} }