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!
This commit is contained in:
Richard Feldman 2021-08-05 22:59:10 -04:00
parent 1a9ca334f6
commit 8d99a0d71d
2 changed files with 47 additions and 12 deletions

View file

@ -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") {

View file

@ -20,11 +20,24 @@ fn main() -> io::Result<()> {
let matches = build_app().get_matches();
let exit_code = match matches.subcommand_name() {
None => {
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!
build(
&Triple::host(),
&matches,
BuildConfig::BuildAndRun { roc_file_arg_index },
)
}
None => {
launch_editor(&[])?;
// rustc couldn't infer the error type here
Result::<i32, io::Error>::Ok(0)
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()?;