mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Check if there was no list of Roc modules to generate docs for, and if not, then search for all roc modules under the current directory
This commit is contained in:
parent
6d00171cd7
commit
5442eba044
2 changed files with 43 additions and 7 deletions
|
@ -94,7 +94,7 @@ pub fn build_app<'a>() -> App<'a> {
|
||||||
.arg(Arg::with_name(DIRECTORY_OR_FILES)
|
.arg(Arg::with_name(DIRECTORY_OR_FILES)
|
||||||
.index(1)
|
.index(1)
|
||||||
.multiple(true)
|
.multiple(true)
|
||||||
.required(true)
|
.required(false)
|
||||||
.help("The directory or files to build documentation for")
|
.help("The directory or files to build documentation for")
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,6 +9,7 @@ use target_lexicon::Triple;
|
||||||
|
|
||||||
#[cfg(feature = "llvm")]
|
#[cfg(feature = "llvm")]
|
||||||
use roc_cli::build;
|
use roc_cli::build;
|
||||||
|
use std::ffi::{OsStr, OsString};
|
||||||
|
|
||||||
#[cfg(not(feature = "llvm"))]
|
#[cfg(not(feature = "llvm"))]
|
||||||
fn build(_target: &Triple, _matches: &clap::ArgMatches, _config: BuildConfig) -> io::Result<i32> {
|
fn build(_target: &Triple, _matches: &clap::ArgMatches, _config: BuildConfig) -> io::Result<i32> {
|
||||||
|
@ -68,19 +69,34 @@ fn main() -> io::Result<()> {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
Some(CMD_DOCS) => {
|
Some(CMD_DOCS) => {
|
||||||
let values = matches
|
let maybe_values = matches
|
||||||
.subcommand_matches(CMD_DOCS)
|
.subcommand_matches(CMD_DOCS)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.values_of_os(DIRECTORY_OR_FILES)
|
.values_of_os(DIRECTORY_OR_FILES);
|
||||||
.unwrap();
|
|
||||||
|
let mut values: Vec<OsString> = Vec::new();
|
||||||
|
|
||||||
|
match maybe_values {
|
||||||
|
None => {
|
||||||
|
let mut os_string_values: Vec<OsString> = Vec::new();
|
||||||
|
read_all_roc_files(&OsStr::new("./").to_os_string(), &mut os_string_values)?;
|
||||||
|
for os_string in os_string_values {
|
||||||
|
values.push(os_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(os_values) => {
|
||||||
|
for os_str in os_values {
|
||||||
|
values.push(os_str.to_os_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut roc_files = Vec::new();
|
let mut roc_files = Vec::new();
|
||||||
|
|
||||||
// Populate roc_files
|
// Populate roc_files
|
||||||
for os_str in values {
|
for os_str in values {
|
||||||
let metadata = fs::metadata(os_str)?;
|
let metadata = fs::metadata(os_str.clone())?;
|
||||||
|
roc_files_recursive(os_str.as_os_str(), metadata.file_type(), &mut roc_files)?;
|
||||||
roc_files_recursive(os_str, metadata.file_type(), &mut roc_files)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
docs(roc_files);
|
docs(roc_files);
|
||||||
|
@ -93,6 +109,26 @@ fn main() -> io::Result<()> {
|
||||||
std::process::exit(exit_code);
|
std::process::exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_all_roc_files(
|
||||||
|
dir: &OsString,
|
||||||
|
mut roc_file_paths: &mut Vec<OsString>,
|
||||||
|
) -> Result<(), std::io::Error> {
|
||||||
|
let entries = fs::read_dir(dir)?;
|
||||||
|
|
||||||
|
for entry in entries {
|
||||||
|
let path = entry?.path();
|
||||||
|
|
||||||
|
if path.is_dir() {
|
||||||
|
read_all_roc_files(&path.into_os_string(), &mut roc_file_paths)?;
|
||||||
|
} else if path.extension().and_then(OsStr::to_str) == Some("roc") {
|
||||||
|
let file_path = path.into_os_string();
|
||||||
|
roc_file_paths.push(file_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn roc_files_recursive<P: AsRef<Path>>(
|
fn roc_files_recursive<P: AsRef<Path>>(
|
||||||
path: P,
|
path: P,
|
||||||
file_type: FileType,
|
file_type: FileType,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue