mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Use matches_of_os for file paths
This commit is contained in:
parent
71fa8c6ee2
commit
e3865a3679
2 changed files with 23 additions and 29 deletions
|
@ -3,16 +3,15 @@ extern crate const_format;
|
||||||
|
|
||||||
use build::BuiltFile;
|
use build::BuiltFile;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use clap::Command;
|
use clap::{Arg, ArgMatches, Command};
|
||||||
use clap::{Arg, ArgMatches};
|
|
||||||
use roc_build::link::LinkType;
|
use roc_build::link::LinkType;
|
||||||
use roc_error_macros::user_error;
|
use roc_error_macros::user_error;
|
||||||
use roc_load::{LoadingProblem, Threading};
|
use roc_load::{LoadingProblem, Threading};
|
||||||
use roc_mono::ir::OptLevel;
|
use roc_mono::ir::OptLevel;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::process;
|
use std::process;
|
||||||
use target_lexicon::BinaryFormat;
|
use target_lexicon::BinaryFormat;
|
||||||
use target_lexicon::{
|
use target_lexicon::{
|
||||||
|
@ -96,6 +95,17 @@ pub fn build_app<'a>() -> Command<'a> {
|
||||||
.possible_values(["true", "false"])
|
.possible_values(["true", "false"])
|
||||||
.required(false);
|
.required(false);
|
||||||
|
|
||||||
|
let roc_file_to_run = Arg::new(ROC_FILE)
|
||||||
|
.help("The .roc file of an app to run")
|
||||||
|
.allow_invalid_utf8(true)
|
||||||
|
.required(true);
|
||||||
|
|
||||||
|
let args_for_app = Arg::new(ARGS_FOR_APP)
|
||||||
|
.help("Arguments to pass into the app being run")
|
||||||
|
.requires(ROC_FILE)
|
||||||
|
.allow_invalid_utf8(true)
|
||||||
|
.multiple_values(true);
|
||||||
|
|
||||||
let app = Command::new("roc")
|
let app = Command::new("roc")
|
||||||
.version(concatcp!(VERSION, "\n"))
|
.version(concatcp!(VERSION, "\n"))
|
||||||
.about("Runs the given .roc file, if there are no compilation errors.\nUse one of the SUBCOMMANDS below to do something else!")
|
.about("Runs the given .roc file, if there are no compilation errors.\nUse one of the SUBCOMMANDS below to do something else!")
|
||||||
|
@ -132,6 +142,7 @@ pub fn build_app<'a>() -> Command<'a> {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(ROC_FILE)
|
Arg::new(ROC_FILE)
|
||||||
.help("The .roc file to build")
|
.help("The .roc file to build")
|
||||||
|
.allow_invalid_utf8(true)
|
||||||
.required(true),
|
.required(true),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -148,17 +159,8 @@ pub fn build_app<'a>() -> Command<'a> {
|
||||||
.arg(flag_linker.clone())
|
.arg(flag_linker.clone())
|
||||||
.arg(flag_precompiled.clone())
|
.arg(flag_precompiled.clone())
|
||||||
.arg(flag_valgrind.clone())
|
.arg(flag_valgrind.clone())
|
||||||
.arg(
|
.arg(roc_file_to_run.clone())
|
||||||
Arg::new(ROC_FILE)
|
.arg(args_for_app.clone())
|
||||||
.help("The .roc file of an app to run")
|
|
||||||
.required(true),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new(ARGS_FOR_APP)
|
|
||||||
.help("Arguments to pass into the app being run")
|
|
||||||
.requires(ROC_FILE)
|
|
||||||
.multiple_values(true),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.subcommand(Command::new(CMD_FORMAT)
|
.subcommand(Command::new(CMD_FORMAT)
|
||||||
.about("Format a .roc file using standard Roc formatting")
|
.about("Format a .roc file using standard Roc formatting")
|
||||||
|
@ -183,6 +185,7 @@ pub fn build_app<'a>() -> Command<'a> {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(ROC_FILE)
|
Arg::new(ROC_FILE)
|
||||||
.help("The .roc file of an app to check")
|
.help("The .roc file of an app to check")
|
||||||
|
.allow_invalid_utf8(true)
|
||||||
.required(true),
|
.required(true),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -206,17 +209,8 @@ pub fn build_app<'a>() -> Command<'a> {
|
||||||
.arg(flag_linker)
|
.arg(flag_linker)
|
||||||
.arg(flag_precompiled)
|
.arg(flag_precompiled)
|
||||||
.arg(flag_valgrind)
|
.arg(flag_valgrind)
|
||||||
.arg(
|
.arg(roc_file_to_run)
|
||||||
Arg::new(ROC_FILE)
|
.arg(args_for_app);
|
||||||
.help("The .roc file of an app to build and run")
|
|
||||||
.required(false),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::new(ARGS_FOR_APP)
|
|
||||||
.help("Arguments to pass into the app being run")
|
|
||||||
.requires(ROC_FILE)
|
|
||||||
.multiple_values(true),
|
|
||||||
);
|
|
||||||
|
|
||||||
if cfg!(feature = "editor") {
|
if cfg!(feature = "editor") {
|
||||||
app.subcommand(
|
app.subcommand(
|
||||||
|
@ -261,7 +255,7 @@ pub fn build(
|
||||||
use BuildConfig::*;
|
use BuildConfig::*;
|
||||||
|
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let filename = matches.value_of(ROC_FILE).unwrap();
|
let filename = matches.value_of_os(ROC_FILE).unwrap();
|
||||||
|
|
||||||
let original_cwd = std::env::current_dir()?;
|
let original_cwd = std::env::current_dir()?;
|
||||||
let opt_level = match (
|
let opt_level = match (
|
||||||
|
@ -466,7 +460,7 @@ pub fn build(
|
||||||
"warnings"
|
"warnings"
|
||||||
},
|
},
|
||||||
total_time.as_millis(),
|
total_time.as_millis(),
|
||||||
filename
|
filename.to_string_lossy()
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(problems.exit_code())
|
Ok(problems.exit_code())
|
||||||
|
|
|
@ -81,7 +81,7 @@ fn main() -> io::Result<()> {
|
||||||
let arena = bumpalo::Bump::new();
|
let arena = bumpalo::Bump::new();
|
||||||
|
|
||||||
let emit_timings = matches.is_present(FLAG_TIME);
|
let emit_timings = matches.is_present(FLAG_TIME);
|
||||||
let filename = matches.value_of(ROC_FILE).unwrap();
|
let filename = matches.value_of_os(ROC_FILE).unwrap();
|
||||||
let roc_file_path = PathBuf::from(filename);
|
let roc_file_path = PathBuf::from(filename);
|
||||||
let src_dir = roc_file_path.parent().unwrap().to_owned();
|
let src_dir = roc_file_path.parent().unwrap().to_owned();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue