Add --include-dependencies to 'aiken docs'

Fixes #867.
This commit is contained in:
KtorZ 2024-03-09 22:35:38 +01:00
parent 37627e3527
commit 80a9393db7
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
4 changed files with 23 additions and 5 deletions

View File

@ -18,6 +18,7 @@
- **aiken-lang**: added serde to CheckedModule to encode modules as cbor. @rvcas - **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-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 `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 ### Fixed

View File

@ -1842,7 +1842,11 @@ impl<'a> Documentable<'a> for &'a ArgName {
} }
fn pub_(public: bool) -> Document<'static> { 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 { impl<'a> Documentable<'a> for &'a UnqualifiedImport {

View File

@ -180,7 +180,11 @@ where
self.compile(options) self.compile(options)
} }
pub fn docs(&mut self, destination: Option<PathBuf>) -> Result<(), Vec<Error>> { pub fn docs(
&mut self,
destination: Option<PathBuf>,
include_dependencies: bool,
) -> Result<(), Vec<Error>> {
self.compile_deps()?; self.compile_deps()?;
self.event_listener self.event_listener
@ -205,7 +209,9 @@ where
let modules = self let modules = self
.checked_modules .checked_modules
.values_mut() .values_mut()
.filter(|CheckedModule { package, .. }| package == &self.config.name.to_string()) .filter(|CheckedModule { package, .. }| {
include_dependencies || package == &self.config.name.to_string()
})
.map(|m| { .map(|m| {
m.attach_doc_and_module_comments(); m.attach_doc_and_module_comments();
&*m &*m

View File

@ -15,6 +15,10 @@ pub struct Args {
#[clap(short, long)] #[clap(short, long)]
watch: bool, watch: bool,
/// When enabled, also generate documentation from dependencies.
#[clap(long)]
include_dependencies: bool,
/// Output directory for the documentation /// Output directory for the documentation
#[clap(short = 'o', long)] #[clap(short = 'o', long)]
destination: Option<PathBuf>, destination: Option<PathBuf>,
@ -26,14 +30,17 @@ pub fn exec(
deny, deny,
watch, watch,
destination, destination,
include_dependencies,
}: Args, }: Args,
) -> miette::Result<()> { ) -> miette::Result<()> {
let result = if watch { let result = if watch {
watch_project(directory.as_deref(), watch::default_filter, 500, |p| { watch_project(directory.as_deref(), watch::default_filter, 500, |p| {
p.docs(destination.clone()) p.docs(destination.clone(), include_dependencies)
}) })
} else { } 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)) result.map_err(|_| process::exit(1))