Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CLI entry point #2157

Merged
merged 14 commits into from
Apr 21, 2019
Prev Previous commit
Next Next commit
rename rest_argv to argv
  • Loading branch information
bartlomieju committed Apr 21, 2019
commit 80ef15dd3ffe23599403d246a7c857ca0e52debb
34 changes: 17 additions & 17 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::state::ThreadSafeState;
use crate::worker::root_specifier_to_url;
use crate::worker::Worker;
use deno::v8_set_flags;
use flags::{create_cli_app, DenoFlags};
use flags::DenoFlags;
use futures::lazy;
use futures::Future;
use log::{LevelFilter, Metadata, Record};
Expand Down Expand Up @@ -128,9 +128,9 @@ pub fn print_file_info(worker: &Worker, url: &str) {

fn get_worker_and_state(
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
flags: DenoFlags,
rest_argv: Vec<String>,
argv: Vec<String>,
) -> (Worker, ThreadSafeState) {
let state = ThreadSafeState::new(flags, rest_argv, ops::op_selector_std);
let state = ThreadSafeState::new(flags, argv, ops::op_selector_std);
let worker = Worker::new(
"main".to_string(),
startup_data::deno_isolate_init(),
Expand Down Expand Up @@ -264,9 +264,10 @@ fn main() {

log::set_logger(&LOGGER).unwrap();
let args: Vec<String> = env::args().collect();
let cli_app = create_cli_app();
let cli_app = flags::create_cli_app();
let matches = cli_app.get_matches_from(args);
let flags = flags::parse_flags(matches.clone());
let mut argv: Vec<String> = vec!["deno".to_string()];

if flags.v8_help {
// show v8 help and exit
Expand All @@ -286,37 +287,36 @@ fn main() {
LevelFilter::Warn
});

let mut rest_argv: Vec<String> = vec!["deno".to_string()];
match matches.subcommand() {
("types", Some(_)) => {
types_command();
}
("eval", Some(info_match)) => {
let code: &str = info_match.value_of("code").unwrap();
rest_argv.extend(vec![code.to_string()]);
eval_command(flags, rest_argv);
argv.extend(vec![code.to_string()]);
eval_command(flags, argv);
}
("info", Some(info_match)) => {
let file: &str = info_match.value_of("file").unwrap();
rest_argv.extend(vec![file.to_string()]);
prefetch_or_info_command(flags, rest_argv, true);
argv.extend(vec![file.to_string()]);
prefetch_or_info_command(flags, argv, true);
}
("prefetch", Some(info_match)) => {
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
let file: &str = info_match.value_of("file").unwrap();
rest_argv.extend(vec![file.to_string()]);
prefetch_or_info_command(flags, rest_argv, false);
argv.extend(vec![file.to_string()]);
prefetch_or_info_command(flags, argv, false);
}
("fmt", Some(fmt_match)) => {
let files: Vec<String> = fmt_match
.values_of("files")
.unwrap()
.map(String::from)
.collect();
rest_argv.extend(files);
fmt_command(flags, rest_argv);
argv.extend(files);
fmt_command(flags, argv);
}
(script, Some(script_match)) => {
rest_argv.extend(vec![script.to_string()]);
argv.extend(vec![script.to_string()]);
// check if there are any extra arguments that should
// be passed to script
if script_match.is_present("") {
Expand All @@ -325,12 +325,12 @@ fn main() {
.unwrap()
.map(String::from)
.collect();
rest_argv.extend(script_args);
argv.extend(script_args);
}
run_script(flags, rest_argv);
run_script(flags, argv);
}
_ => {
run_repl(flags, rest_argv);
run_repl(flags, argv);
}
}
}