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**: 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

View File

@ -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 {

View File

@ -180,7 +180,11 @@ where
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.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

View File

@ -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<PathBuf>,
@ -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))