|
@@ -52,9 +52,11 @@ impl<'a> Builder<'a> {
|
|
|
// requirement: links MUST be set and MUST match the name
|
|
|
let _links = build_var("CARGO_MANIFEST_LINKS")?;
|
|
|
|
|
|
- let autogenerated = Path::new("permissions/autogenerated/");
|
|
|
+ let autogenerated = Path::new("permissions/autogenerated");
|
|
|
let commands_dir = &autogenerated.join("commands");
|
|
|
|
|
|
+ std::fs::create_dir_all(&autogenerated).expect("unable to create permissions dir");
|
|
|
+
|
|
|
if !self.commands.is_empty() {
|
|
|
acl::build::autogenerate_command_permissions(commands_dir, self.commands, "");
|
|
|
}
|
|
@@ -62,6 +64,7 @@ impl<'a> Builder<'a> {
|
|
|
let permissions = acl::build::define_permissions("./permissions/**/*.*", &name, &out_dir)?;
|
|
|
|
|
|
acl::build::generate_schema(&permissions, "./permissions")?;
|
|
|
+ generate_docs(&permissions, &autogenerated)?;
|
|
|
|
|
|
if let Some(global_scope_schema) = self.global_scope_schema {
|
|
|
acl::build::define_global_scope_schema(global_scope_schema, &name, &out_dir)?;
|
|
@@ -74,6 +77,42 @@ impl<'a> Builder<'a> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+fn generate_docs(permissions: &[acl::plugin::PermissionFile], out_dir: &Path) -> Result<(), Error> {
|
|
|
+ let mut docs = format!("# Permissions\n\n");
|
|
|
+
|
|
|
+ fn docs_from(id: &str, description: Option<&str>) -> String {
|
|
|
+ let mut docs = format!("## {id}");
|
|
|
+ if let Some(d) = description {
|
|
|
+ docs.push_str(&format!("\n\n{d}"));
|
|
|
+ }
|
|
|
+ docs
|
|
|
+ }
|
|
|
+
|
|
|
+ for permission in permissions {
|
|
|
+ for set in &permission.set {
|
|
|
+ docs.push_str(&docs_from(&set.identifier, Some(&set.description)));
|
|
|
+ docs.push_str("\n\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ if let Some(default) = &permission.default {
|
|
|
+ docs.push_str(&docs_from("default", default.description.as_deref()));
|
|
|
+ docs.push_str("\n\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ for permission in &permission.permission {
|
|
|
+ docs.push_str(&docs_from(
|
|
|
+ &permission.identifier,
|
|
|
+ permission.description.as_deref(),
|
|
|
+ ));
|
|
|
+ docs.push_str("\n\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ std::fs::write(out_dir.join("reference.md"), docs).map_err(Error::WriteFile)?;
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
+
|
|
|
/// Grab an env var that is expected to be set inside of build scripts.
|
|
|
fn build_var(key: &'static str) -> Result<String, Error> {
|
|
|
std::env::var(key).map_err(|_| Error::BuildVar(key))
|