From 80a9393db784a0bbc26886a3a604ae71daa1129e Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sat, 9 Mar 2024 22:35:38 +0100 Subject: [PATCH] Add --include-dependencies to 'aiken docs' Fixes #867. --- CHANGELOG.md | 1 + crates/aiken-lang/src/format.rs | 6 +++++- crates/aiken-project/src/lib.rs | 10 ++++++++-- crates/aiken/src/cmd/docs.rs | 11 +++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d87793d0..0b896313 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - **aiken-lang**: added serde to CheckedModule to encode modules as cbor. @rvcas - **aiken-lang**: Strings can contain a nul byte using the escape sequence `\0`. @KtorZ - **aiken**: The `check` command now accept an extra (optional) option `--max-success` to control the number of property-test iterations to perform. @KtorZ +- **aiken**: The `docs` command now accept an optional flag `--include-dependencies` to include all dependencies in the generated documentation. @KtorZ ### Fixed diff --git a/crates/aiken-lang/src/format.rs b/crates/aiken-lang/src/format.rs index de8fb8c8..ee06815c 100644 --- a/crates/aiken-lang/src/format.rs +++ b/crates/aiken-lang/src/format.rs @@ -1842,7 +1842,11 @@ impl<'a> Documentable<'a> for &'a ArgName { } fn pub_(public: bool) -> Document<'static> { - if public { "pub ".to_doc() } else { nil() } + if public { + "pub ".to_doc() + } else { + nil() + } } impl<'a> Documentable<'a> for &'a UnqualifiedImport { diff --git a/crates/aiken-project/src/lib.rs b/crates/aiken-project/src/lib.rs index e1dae028..a8fba735 100644 --- a/crates/aiken-project/src/lib.rs +++ b/crates/aiken-project/src/lib.rs @@ -180,7 +180,11 @@ where self.compile(options) } - pub fn docs(&mut self, destination: Option) -> Result<(), Vec> { + pub fn docs( + &mut self, + destination: Option, + include_dependencies: bool, + ) -> Result<(), Vec> { self.compile_deps()?; self.event_listener @@ -205,7 +209,9 @@ where let modules = self .checked_modules .values_mut() - .filter(|CheckedModule { package, .. }| package == &self.config.name.to_string()) + .filter(|CheckedModule { package, .. }| { + include_dependencies || package == &self.config.name.to_string() + }) .map(|m| { m.attach_doc_and_module_comments(); &*m diff --git a/crates/aiken/src/cmd/docs.rs b/crates/aiken/src/cmd/docs.rs index 1abc27db..fbc3ac18 100644 --- a/crates/aiken/src/cmd/docs.rs +++ b/crates/aiken/src/cmd/docs.rs @@ -15,6 +15,10 @@ pub struct Args { #[clap(short, long)] watch: bool, + /// When enabled, also generate documentation from dependencies. + #[clap(long)] + include_dependencies: bool, + /// Output directory for the documentation #[clap(short = 'o', long)] destination: Option, @@ -26,14 +30,17 @@ pub fn exec( deny, watch, destination, + include_dependencies, }: Args, ) -> miette::Result<()> { let result = if watch { watch_project(directory.as_deref(), watch::default_filter, 500, |p| { - p.docs(destination.clone()) + p.docs(destination.clone(), include_dependencies) }) } else { - with_project(directory.as_deref(), deny, |p| p.docs(destination.clone())) + with_project(directory.as_deref(), deny, |p| { + p.docs(destination.clone(), include_dependencies) + }) }; result.map_err(|_| process::exit(1))