mirror of
https://github.com/roc-lang/roc.git
synced 2024-08-17 06:41:22 +03:00
Add --output CLI flag for roc docs
This commit is contained in:
parent
77d2136d00
commit
a96752a65a
@ -63,6 +63,7 @@ pub const FLAG_LINKER: &str = "linker";
|
|||||||
pub const FLAG_PREBUILT: &str = "prebuilt-platform";
|
pub const FLAG_PREBUILT: &str = "prebuilt-platform";
|
||||||
pub const FLAG_CHECK: &str = "check";
|
pub const FLAG_CHECK: &str = "check";
|
||||||
pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb";
|
pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb";
|
||||||
|
pub const FLAG_OUTPUT: &str = "output";
|
||||||
pub const ROC_FILE: &str = "ROC_FILE";
|
pub const ROC_FILE: &str = "ROC_FILE";
|
||||||
pub const ROC_DIR: &str = "ROC_DIR";
|
pub const ROC_DIR: &str = "ROC_DIR";
|
||||||
pub const GLUE_DIR: &str = "GLUE_DIR";
|
pub const GLUE_DIR: &str = "GLUE_DIR";
|
||||||
@ -71,6 +72,7 @@ pub const DIRECTORY_OR_FILES: &str = "DIRECTORY_OR_FILES";
|
|||||||
pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP";
|
pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP";
|
||||||
|
|
||||||
const VERSION: &str = include_str!("../../../version.txt");
|
const VERSION: &str = include_str!("../../../version.txt");
|
||||||
|
const DEFAULT_GENERATED_DOCS_DIR: &str = "generated-docs";
|
||||||
|
|
||||||
pub fn build_app() -> Command {
|
pub fn build_app() -> Command {
|
||||||
let flag_optimize = Arg::new(FLAG_OPTIMIZE)
|
let flag_optimize = Arg::new(FLAG_OPTIMIZE)
|
||||||
@ -276,6 +278,13 @@ pub fn build_app() -> Command {
|
|||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new(CMD_DOCS)
|
Command::new(CMD_DOCS)
|
||||||
.about("Generate documentation for a Roc package")
|
.about("Generate documentation for a Roc package")
|
||||||
|
.arg(Arg::new(FLAG_OUTPUT)
|
||||||
|
.long(FLAG_OUTPUT)
|
||||||
|
.help("Output directory for the generated documentation files.")
|
||||||
|
.value_parser(value_parser!(OsString))
|
||||||
|
.required(false)
|
||||||
|
.default_value(DEFAULT_GENERATED_DOCS_DIR),
|
||||||
|
)
|
||||||
.arg(Arg::new(ROC_FILE)
|
.arg(Arg::new(ROC_FILE)
|
||||||
.help("The package's main .roc file")
|
.help("The package's main .roc file")
|
||||||
.value_parser(value_parser!(PathBuf))
|
.value_parser(value_parser!(PathBuf))
|
||||||
|
@ -4,8 +4,8 @@ use roc_build::program::{check_file, CodeGenBackend};
|
|||||||
use roc_cli::{
|
use roc_cli::{
|
||||||
build_app, format, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, CMD_DEV, CMD_DOCS,
|
build_app, format, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, CMD_DEV, CMD_DOCS,
|
||||||
CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST, CMD_VERSION,
|
CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_REPL, CMD_RUN, CMD_TEST, CMD_VERSION,
|
||||||
DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_NO_LINK, FLAG_TARGET, FLAG_TIME,
|
DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_NO_LINK, FLAG_OUTPUT, FLAG_TARGET,
|
||||||
GLUE_DIR, GLUE_SPEC, ROC_FILE,
|
FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE,
|
||||||
};
|
};
|
||||||
use roc_docs::generate_docs_html;
|
use roc_docs::generate_docs_html;
|
||||||
use roc_error_macros::user_error;
|
use roc_error_macros::user_error;
|
||||||
@ -213,8 +213,9 @@ fn main() -> io::Result<()> {
|
|||||||
Some((CMD_REPL, _)) => Ok(roc_repl_cli::main()),
|
Some((CMD_REPL, _)) => Ok(roc_repl_cli::main()),
|
||||||
Some((CMD_DOCS, matches)) => {
|
Some((CMD_DOCS, matches)) => {
|
||||||
let root_path = matches.get_one::<PathBuf>(ROC_FILE).unwrap();
|
let root_path = matches.get_one::<PathBuf>(ROC_FILE).unwrap();
|
||||||
|
let out_dir = matches.get_one::<OsString>(FLAG_OUTPUT).unwrap();
|
||||||
|
|
||||||
generate_docs_html(root_path.to_owned());
|
generate_docs_html(root_path.to_owned(), out_dir.as_ref());
|
||||||
|
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,9 @@ use roc_region::all::Region;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
const BUILD_DIR: &str = "./generated-docs";
|
|
||||||
|
|
||||||
const LINK_SVG: &str = include_str!("./static/link.svg");
|
const LINK_SVG: &str = include_str!("./static/link.svg");
|
||||||
|
|
||||||
pub fn generate_docs_html(root_file: PathBuf) {
|
pub fn generate_docs_html(root_file: PathBuf, build_dir: &Path) {
|
||||||
let build_dir = Path::new(BUILD_DIR);
|
|
||||||
let loaded_module = load_module_for_docs(root_file);
|
let loaded_module = load_module_for_docs(root_file);
|
||||||
|
|
||||||
// TODO get these from the platform's source file rather than hardcoding them!
|
// TODO get these from the platform's source file rather than hardcoding them!
|
||||||
|
@ -20,7 +20,10 @@ fn main() -> io::Result<()> {
|
|||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
// Populate roc_files
|
// Populate roc_files
|
||||||
generate_docs_html(matches.get_one::<PathBuf>(ROC_FILE).unwrap().to_owned());
|
generate_docs_html(
|
||||||
|
matches.get_one::<PathBuf>(ROC_FILE).unwrap().to_owned(),
|
||||||
|
&PathBuf::from("./generated-docs"),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user