mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Merge pull request #1532 from rtfeldman/roc-run-without-run
`roc run [FILE]` is now `roc [FILE]`
This commit is contained in:
commit
afcfe773b6
8 changed files with 68 additions and 29 deletions
|
@ -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.
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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,9 +35,10 @@ 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"))
|
||||
.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")
|
||||
|
@ -43,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(
|
||||
|
@ -60,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)
|
||||
|
@ -76,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(
|
||||
|
@ -98,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") {
|
||||
|
@ -215,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.
|
||||
|
@ -263,16 +293,16 @@ fn roc_run(cmd: &mut Command) -> io::Result<i32> {
|
|||
.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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<i32, io::Error>::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()?;
|
||||
|
|
|
@ -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.
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue