Skip to content

Commit

Permalink
Create draft UI for roc init
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinCamarasa committed Nov 6, 2024
1 parent 69dd8d7 commit da0b807
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
18 changes: 18 additions & 0 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 19 additions & 5 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,6 +101,20 @@ fn main() -> io::Result<()> {
Ok(1)
}
}
Some((CMD_INIT, matches)) => {
let _platform_path = matches.get_one::<PathBuf>(ROC_PLATFORM).unwrap();
let output_path = matches.get_one::<PathBuf>(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::<PathBuf>(ROC_FILE).unwrap();
let output_path = matches.get_one::<PathBuf>(GLUE_DIR).unwrap();
Expand Down

0 comments on commit da0b807

Please sign in to comment.