From 6c846299c81b419973e2bb4d40e3d142998fb66c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Aug 2021 22:24:14 -0400 Subject: [PATCH 1/4] Print a newline after the --version Otherwise various shells are unhappy --- cli/Cargo.toml | 2 +- cli/src/lib.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 5d1d5b165d..8288d26d6f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -57,7 +57,7 @@ roc_reporting = { path = "../compiler/reporting" } roc_editor = { path = "../editor", optional = true } # TODO switch to clap 3.0.0 once it's out. Tried adding clap = "~3.0.0-beta.1" and cargo wouldn't accept it clap = { git = "https://github.com/rtfeldman/clap", branch = "master" } -const_format = "0.2.8" +const_format = "0.2" rustyline = { git = "https://github.com/rtfeldman/rustyline", tag = "prompt-fix" } rustyline-derive = { git = "https://github.com/rtfeldman/rustyline", tag = "prompt-fix" } im = "14" # im and im-rc should always have the same version! diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 64956980d8..a5d38c80e3 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -1,6 +1,9 @@ #[macro_use] extern crate clap; +#[macro_use] +extern crate const_format; + use build::{BuildOutcome, BuiltFile}; use bumpalo::Bump; use clap::{App, AppSettings, Arg, ArgMatches}; @@ -32,7 +35,7 @@ pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP"; pub fn build_app<'a>() -> App<'a> { let app = App::new("roc") - .version(crate_version!()) + .version(concatcp!(crate_version!(), "\n")) .subcommand(App::new(CMD_BUILD) .about("Build a program") .arg( From 1a9ca334f6f9ce6a6178a995204bcc16e1fd7b7e Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Aug 2021 22:59:05 -0400 Subject: [PATCH 2/4] Update some CLI docs --- cli/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index a5d38c80e3..2c83b7b12b 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -36,8 +36,9 @@ pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP"; pub fn build_app<'a>() -> App<'a> { let app = App::new("roc") .version(concatcp!(crate_version!(), "\n")) + .about("Runs the given .roc file. Use one of the SUBCOMMANDS below to do something else!") .subcommand(App::new(CMD_BUILD) - .about("Build a program") + .about("Build a binary from the given .roc file, but don't run it") .arg( Arg::with_name(ROC_FILE) .help("The .roc file to build") @@ -46,7 +47,7 @@ pub fn build_app<'a>() -> App<'a> { .arg( Arg::with_name(FLAG_OPTIMIZE) .long(FLAG_OPTIMIZE) - .help("Optimize the compiled program to run faster. (Optimization takes time to complete.)") + .help("Optimize your compiled Roc program to run faster. (Optimization takes time to complete.)") .required(false), ) .arg( From 8d99a0d71d38699a771441a2cf9b1ba3f9748f31 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Aug 2021 22:59:10 -0400 Subject: [PATCH 3/4] Instead of `roc run [FILE]` just do `roc [FILE]` This is relevant because it lets us run scripts using: !#/usr/bin/env roc ...instead of: !#/usr/bin/env roc run ...which is not supported in all `env` implementations! --- cli/src/lib.rs | 30 ++++++++++++++++++++++++++++-- cli/src/main.rs | 29 +++++++++++++++++++---------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 2c83b7b12b..cbfbf38e10 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -64,7 +64,7 @@ pub fn build_app<'a>() -> App<'a> { ) ) .subcommand(App::new(CMD_RUN) - .about("Build and run a program") + .about("DEPRECATED - now use `roc [FILE]` instead of `roc run [FILE]`") .setting(AppSettings::TrailingVarArg) .arg( Arg::with_name(FLAG_OPTIMIZE) @@ -80,7 +80,7 @@ pub fn build_app<'a>() -> App<'a> { ) .arg( Arg::with_name(ROC_FILE) - .help("The .roc file of an app to build and run") + .help("The .roc file of an app to run") .required(true), ) .arg( @@ -102,6 +102,32 @@ pub fn build_app<'a>() -> App<'a> { .help("The directory or files to build documentation for") ) + ) + .setting(AppSettings::TrailingVarArg) + .arg( + Arg::with_name(FLAG_OPTIMIZE) + .long(FLAG_OPTIMIZE) + .help("Optimize the compiled program to run faster. (Optimization takes time to complete.)") + .requires(ROC_FILE) + .required(false), + ) + .arg( + Arg::with_name(FLAG_DEBUG) + .long(FLAG_DEBUG) + .help("Store LLVM debug information in the generated program") + .requires(ROC_FILE) + .required(false), + ) + .arg( + Arg::with_name(ROC_FILE) + .help("The .roc file of an app to build and run") + .required(false), + ) + .arg( + Arg::with_name(ARGS_FOR_APP) + .help("Arguments to pass into the app being run") + .requires(ROC_FILE) + .multiple(true), ); if cfg!(feature = "editor") { diff --git a/cli/src/main.rs b/cli/src/main.rs index c4d659a5be..b7bacb92d6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -21,10 +21,23 @@ fn main() -> io::Result<()> { let exit_code = match matches.subcommand_name() { None => { - launch_editor(&[])?; + match matches.index_of(ROC_FILE) { + Some(arg_index) => { + let roc_file_arg_index = arg_index + 1; // Not sure why this +1 is necessary, but it is! - // rustc couldn't infer the error type here - Result::::Ok(0) + build( + &Triple::host(), + &matches, + BuildConfig::BuildAndRun { roc_file_arg_index }, + ) + } + + None => { + launch_editor(&[])?; + + Ok(0) + } + } } Some(CMD_BUILD) => Ok(build( &Triple::host(), @@ -32,14 +45,10 @@ fn main() -> io::Result<()> { BuildConfig::BuildOnly, )?), Some(CMD_RUN) => { - let subcmd_matches = matches.subcommand_matches(CMD_RUN).unwrap(); - let roc_file_arg_index = subcmd_matches.index_of(ROC_FILE).unwrap() + 1; // Not sure why this +1 is necessary, but it is! + // TODO remove CMD_RUN altogether if it is currently September 2021 or later. + println!("`roc run` is deprecated! (You no longer need the `run` - just do `roc [FILE]` instead of `roc run [FILE]` like before."); - Ok(build( - &Triple::host(), - subcmd_matches, - BuildConfig::BuildAndRun { roc_file_arg_index }, - )?) + Ok(1) } Some(CMD_REPL) => { repl::main()?; From bc952641eb6426acea0ad10d1ac91af77e30b0ec Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 5 Aug 2021 23:14:59 -0400 Subject: [PATCH 4/4] Update docs to remove references to `roc run` --- README.md | 2 +- cli/src/lib.rs | 8 ++++---- examples/README.md | 4 ++-- examples/hello-world/README.md | 4 ++-- examples/hello-zig/README.md | 4 ++-- examples/quicksort/README.md | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e85f58c2d4..d7ec8900cb 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Run examples as follows: 1. Navigate to `/examples` 2. Run with: ``` -cargo run run hello-world/Hello.roc +cargo run hello-world/Hello.roc ``` Some examples like `examples/benchmarks/NQueens.roc` require input after running. For NQueens, input 10 in the terminal and press enter. diff --git a/cli/src/lib.rs b/cli/src/lib.rs index cbfbf38e10..7eb98bda36 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -245,7 +245,7 @@ pub fn build(target: &Triple, matches: &ArgMatches, config: BuildConfig) -> io:: // Forward all the arguments after the .roc file argument // to the new process. This way, you can do things like: // - // roc run app.roc foo bar baz + // roc app.roc foo bar baz // // ...and have it so that app.roc will receive only `foo`, // `bar`, and `baz` as its arguments. @@ -293,16 +293,16 @@ fn roc_run(cmd: &mut Command) -> io::Result { .spawn() .unwrap_or_else(|err| panic!("Failed to run app after building it: {:?}", err)) .wait() - .expect("TODO gracefully handle block_on failing when roc run spawns a subprocess for the compiled app"); + .expect("TODO gracefully handle block_on failing when `roc` spawns a subprocess for the compiled app"); - // `roc run` exits with the same status code as the app it ran. + // `roc [FILE]` exits with the same status code as the app it ran. // // If you want to know whether there were compilation problems // via status code, use either `roc build` or `roc check` instead! match exit_status.code() { Some(code) => Ok(code), None => { - todo!("TODO gracefully handle the roc run subprocess terminating with a signal."); + todo!("TODO gracefully handle the `roc [FILE]` subprocess terminating with a signal."); } } } diff --git a/examples/README.md b/examples/README.md index 15c5f4e5f1..07e56d7580 100644 --- a/examples/README.md +++ b/examples/README.md @@ -7,7 +7,7 @@ Run examples as follows: 1. Navigate to `/examples` 2. Run with: ``` -cargo run run hello-world/Hello.roc +cargo run hello-world/Hello.roc ``` Some examples like `examples/benchmarks/NQueens.roc` require input after running. -For NQueens, input 10 in the terminal and press enter. \ No newline at end of file +For NQueens, input 10 in the terminal and press enter. diff --git a/examples/hello-world/README.md b/examples/hello-world/README.md index 4aab7c1346..0f1af10077 100644 --- a/examples/hello-world/README.md +++ b/examples/hello-world/README.md @@ -3,13 +3,13 @@ To run, `cd` into this directory and run: ```bash -$ cargo run run Hello.roc +$ cargo run Hello.roc ``` To run in release mode instead, do: ```bash -$ cargo run --release run Hello.roc +$ cargo run --release Hello.roc ``` ## Troubleshooting diff --git a/examples/hello-zig/README.md b/examples/hello-zig/README.md index 4aab7c1346..0f1af10077 100644 --- a/examples/hello-zig/README.md +++ b/examples/hello-zig/README.md @@ -3,13 +3,13 @@ To run, `cd` into this directory and run: ```bash -$ cargo run run Hello.roc +$ cargo run Hello.roc ``` To run in release mode instead, do: ```bash -$ cargo run --release run Hello.roc +$ cargo run --release Hello.roc ``` ## Troubleshooting diff --git a/examples/quicksort/README.md b/examples/quicksort/README.md index c900f17b24..d0c6f2e297 100644 --- a/examples/quicksort/README.md +++ b/examples/quicksort/README.md @@ -3,13 +3,13 @@ To run: ```bash -$ cargo run run Quicksort.roc +$ cargo run Quicksort.roc ``` To run in release mode instead, do: ```bash -$ cargo run --release run Quicksort.roc +$ cargo run --release Quicksort.roc ``` ## Troubleshooting