mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
moved all crates into seperate folder + related path fixes
This commit is contained in:
parent
12ef03bb86
commit
eee85fa45d
1063 changed files with 92 additions and 93 deletions
50
crates/docs_cli/src/main.rs
Normal file
50
crates/docs_cli/src/main.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use clap::{Arg, Command};
|
||||
use roc_docs::generate_docs_html;
|
||||
use std::fs::{self, FileType};
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub const DIRECTORY_OR_FILES: &str = "DIRECTORY_OR_FILES";
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let matches = Command::new("roc-docs")
|
||||
.about("Build HTML documentation files from the given .roc files")
|
||||
.arg(
|
||||
Arg::new(DIRECTORY_OR_FILES)
|
||||
.multiple_values(true)
|
||||
.required(true)
|
||||
.help("The directory or files to build documentation for")
|
||||
.allow_invalid_utf8(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let mut roc_files = Vec::new();
|
||||
|
||||
// Populate roc_files
|
||||
for os_str in matches.values_of_os(DIRECTORY_OR_FILES).unwrap() {
|
||||
let metadata = fs::metadata(os_str)?;
|
||||
roc_files_recursive(os_str, metadata.file_type(), &mut roc_files)?;
|
||||
}
|
||||
|
||||
generate_docs_html(roc_files);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn roc_files_recursive<P: AsRef<Path>>(
|
||||
path: P,
|
||||
file_type: FileType,
|
||||
roc_files: &mut Vec<PathBuf>,
|
||||
) -> io::Result<()> {
|
||||
if file_type.is_dir() {
|
||||
for entry_res in fs::read_dir(path)? {
|
||||
let entry = entry_res?;
|
||||
|
||||
roc_files_recursive(entry.path(), entry.file_type()?, roc_files)?;
|
||||
}
|
||||
} else {
|
||||
roc_files.push(path.as_ref().to_path_buf());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue