diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index a6772b55fe..2efe933667 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -53,6 +53,7 @@ pub const CMD_CHECK: &str = "check"; pub const CMD_VERSION: &str = "version"; pub const CMD_FORMAT: &str = "format"; pub const CMD_TEST: &str = "test"; +pub const CMD_INIT: &str = "init"; pub const CMD_GLUE: &str = "glue"; pub const CMD_GEN_STUB_LIB: &str = "gen-stub-lib"; pub const CMD_PREPROCESS_HOST: &str = "preprocess-host"; @@ -84,6 +85,8 @@ pub const ROC_FILE: &str = "ROC_FILE"; pub const ROC_DIR: &str = "ROC_DIR"; pub const GLUE_DIR: &str = "GLUE_DIR"; pub const GLUE_SPEC: &str = "GLUE_SPEC"; +pub const ROC_PLATFORM: &str = "ROC_PLATFORM"; +pub const INIT_DIR: &str = "INIT_DIR"; pub const DIRECTORY_OR_FILES: &str = "DIRECTORY_OR_FILES"; pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP"; pub const FLAG_PP_HOST: &str = "host"; @@ -381,6 +384,21 @@ pub fn build_app() -> Command { .default_value(DEFAULT_ROC_FILENAME), ) ) + .subcommand(Command::new(CMD_INIT) + .about("Generate a project based on a platform init.roc file") + .arg( + Arg::new(ROC_PLATFORM) + .help("The target platform that provides the init.roc file.") + .value_parser(value_parser!(PathBuf)) + .required(true) + ) + .arg( + Arg::new(INIT_DIR) + .help("The directory for the generated init code.\nNote: The implementation can write to any file in this directory.") + .value_parser(value_parser!(PathBuf)) + .required(true) + ) + ) .subcommand(Command::new(CMD_GLUE) .about("Generate glue code between a platform's Roc API and its host language") .arg(&flag_dev) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index a85f4d5d8c..a32c3174cb 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -4,11 +4,11 @@ use roc_build::link::LinkType; use roc_build::program::{check_file, CodeGenBackend}; use roc_cli::{ build_app, format_files, format_src, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, - CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_PREPROCESS_HOST, CMD_REPL, - CMD_RUN, CMD_TEST, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_MAIN, - FLAG_NO_COLOR, FLAG_NO_HEADER, FLAG_NO_LINK, FLAG_OUTPUT, FLAG_PP_DYLIB, FLAG_PP_HOST, - FLAG_PP_PLATFORM, FLAG_STDIN, FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, - ROC_FILE, VERSION, + CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GEN_STUB_LIB, CMD_GLUE, CMD_INIT, CMD_PREPROCESS_HOST, + CMD_REPL, CMD_RUN, CMD_TEST, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, + FLAG_MAIN, FLAG_NO_COLOR, FLAG_NO_HEADER, FLAG_NO_LINK, FLAG_OUTPUT, FLAG_PP_DYLIB, + FLAG_PP_HOST, FLAG_PP_PLATFORM, FLAG_STDIN, FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, + GLUE_SPEC, INIT_DIR, ROC_FILE, ROC_PLATFORM, VERSION, }; use roc_docs::generate_docs_html; use roc_error_macros::user_error; @@ -101,6 +101,20 @@ fn main() -> io::Result<()> { Ok(1) } } + Some((CMD_INIT, matches)) => { + let _platform_path = matches.get_one::(ROC_PLATFORM).unwrap(); + let output_path = matches.get_one::(INIT_DIR).unwrap(); + + if !output_path.exists() || output_path.is_dir() { + // TODO: implement + eprintln!("This feature is currently being implemented"); + Ok(0) + } else { + eprintln!("`roc init` must be given a directory to output into, because the init might generate multiple files."); + + Ok(1) + } + } Some((CMD_GLUE, matches)) => { let input_path = matches.get_one::(ROC_FILE).unwrap(); let output_path = matches.get_one::(GLUE_DIR).unwrap();