mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
refactor: factor out DenoSubcommand enum variant into structs (#11896)
This commit refactors "DenoSubcommand" enum in a way that variants no longer contain anonymous structures but instead contain dedicated structures for each subcommand, eg. "DenoSubcommand::Lint" now contains "LintSubcommand".
This commit is contained in:
parent
d93570a619
commit
44ca3ce6ae
3 changed files with 520 additions and 519 deletions
651
cli/flags.rs
651
cli/flags.rs
File diff suppressed because it is too large
Load diff
383
cli/main.rs
383
cli/main.rs
|
@ -40,8 +40,23 @@ mod version;
|
||||||
|
|
||||||
use crate::file_fetcher::File;
|
use crate::file_fetcher::File;
|
||||||
use crate::file_watcher::ResolutionResult;
|
use crate::file_watcher::ResolutionResult;
|
||||||
|
use crate::flags::BundleFlags;
|
||||||
|
use crate::flags::CacheFlags;
|
||||||
|
use crate::flags::CompileFlags;
|
||||||
|
use crate::flags::CompletionsFlags;
|
||||||
|
use crate::flags::CoverageFlags;
|
||||||
use crate::flags::DenoSubcommand;
|
use crate::flags::DenoSubcommand;
|
||||||
|
use crate::flags::DocFlags;
|
||||||
|
use crate::flags::EvalFlags;
|
||||||
use crate::flags::Flags;
|
use crate::flags::Flags;
|
||||||
|
use crate::flags::FmtFlags;
|
||||||
|
use crate::flags::InfoFlags;
|
||||||
|
use crate::flags::InstallFlags;
|
||||||
|
use crate::flags::LintFlags;
|
||||||
|
use crate::flags::ReplFlags;
|
||||||
|
use crate::flags::RunFlags;
|
||||||
|
use crate::flags::TestFlags;
|
||||||
|
use crate::flags::UpgradeFlags;
|
||||||
use crate::fmt_errors::PrettyJsError;
|
use crate::fmt_errors::PrettyJsError;
|
||||||
use crate::media_type::MediaType;
|
use crate::media_type::MediaType;
|
||||||
use crate::module_loader::CliModuleLoader;
|
use crate::module_loader::CliModuleLoader;
|
||||||
|
@ -73,7 +88,6 @@ use std::env;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
use std::num::NonZeroUsize;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -365,21 +379,20 @@ pub fn get_types(unstable: bool) -> String {
|
||||||
|
|
||||||
async fn compile_command(
|
async fn compile_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
source_file: String,
|
compile_flags: CompileFlags,
|
||||||
output: Option<PathBuf>,
|
|
||||||
args: Vec<String>,
|
|
||||||
target: Option<String>,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let debug = flags.log_level == Some(log::Level::Debug);
|
let debug = flags.log_level == Some(log::Level::Debug);
|
||||||
|
|
||||||
let run_flags =
|
let run_flags = tools::standalone::compile_to_runtime_flags(
|
||||||
tools::standalone::compile_to_runtime_flags(flags.clone(), args)?;
|
flags.clone(),
|
||||||
|
compile_flags.args,
|
||||||
|
)?;
|
||||||
|
|
||||||
let module_specifier = resolve_url_or_path(&source_file)?;
|
let module_specifier = resolve_url_or_path(&compile_flags.source_file)?;
|
||||||
let program_state = ProgramState::build(flags.clone()).await?;
|
let program_state = ProgramState::build(flags.clone()).await?;
|
||||||
let deno_dir = &program_state.dir;
|
let deno_dir = &program_state.dir;
|
||||||
|
|
||||||
let output = output.or_else(|| {
|
let output = compile_flags.output.or_else(|| {
|
||||||
infer_name_from_url(&module_specifier).map(PathBuf::from)
|
infer_name_from_url(&module_specifier).map(PathBuf::from)
|
||||||
}).ok_or_else(|| generic_error(
|
}).ok_or_else(|| generic_error(
|
||||||
"An executable name was not provided. One could not be inferred from the URL. Aborting.",
|
"An executable name was not provided. One could not be inferred from the URL. Aborting.",
|
||||||
|
@ -408,7 +421,8 @@ async fn compile_command(
|
||||||
|
|
||||||
// Select base binary based on target
|
// Select base binary based on target
|
||||||
let original_binary =
|
let original_binary =
|
||||||
tools::standalone::get_base_binary(deno_dir, target.clone()).await?;
|
tools::standalone::get_base_binary(deno_dir, compile_flags.target.clone())
|
||||||
|
.await?;
|
||||||
|
|
||||||
let final_bin = tools::standalone::create_standalone_binary(
|
let final_bin = tools::standalone::create_standalone_binary(
|
||||||
original_binary,
|
original_binary,
|
||||||
|
@ -418,20 +432,23 @@ async fn compile_command(
|
||||||
|
|
||||||
info!("{} {}", colors::green("Emit"), output.display());
|
info!("{} {}", colors::green("Emit"), output.display());
|
||||||
|
|
||||||
tools::standalone::write_standalone_binary(output.clone(), target, final_bin)
|
tools::standalone::write_standalone_binary(
|
||||||
.await?;
|
output.clone(),
|
||||||
|
compile_flags.target,
|
||||||
|
final_bin,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn info_command(
|
async fn info_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
maybe_specifier: Option<String>,
|
info_flags: InfoFlags,
|
||||||
json: bool,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let location = flags.location.clone();
|
let location = flags.location.clone();
|
||||||
let program_state = ProgramState::build(flags).await?;
|
let program_state = ProgramState::build(flags).await?;
|
||||||
if let Some(specifier) = maybe_specifier {
|
if let Some(specifier) = info_flags.file {
|
||||||
let specifier = resolve_url_or_path(&specifier)?;
|
let specifier = resolve_url_or_path(&specifier)?;
|
||||||
let handler = Arc::new(Mutex::new(specifier_handler::FetchHandler::new(
|
let handler = Arc::new(Mutex::new(specifier_handler::FetchHandler::new(
|
||||||
&program_state,
|
&program_state,
|
||||||
|
@ -452,7 +469,7 @@ async fn info_command(
|
||||||
let graph = builder.get_graph();
|
let graph = builder.get_graph();
|
||||||
let info = graph.info()?;
|
let info = graph.info()?;
|
||||||
|
|
||||||
if json {
|
if info_flags.json {
|
||||||
write_json_to_stdout(&json!(info))
|
write_json_to_stdout(&json!(info))
|
||||||
} else {
|
} else {
|
||||||
write_to_stdout_ignore_sigpipe(info.to_string().as_bytes())
|
write_to_stdout_ignore_sigpipe(info.to_string().as_bytes())
|
||||||
|
@ -460,29 +477,32 @@ async fn info_command(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If it was just "deno info" print location of caches and exit
|
// If it was just "deno info" print location of caches and exit
|
||||||
print_cache_info(&program_state, json, location)
|
print_cache_info(&program_state, info_flags.json, location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn install_command(
|
async fn install_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
module_url: String,
|
install_flags: InstallFlags,
|
||||||
args: Vec<String>,
|
|
||||||
name: Option<String>,
|
|
||||||
root: Option<PathBuf>,
|
|
||||||
force: bool,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let mut preload_flags = flags.clone();
|
let mut preload_flags = flags.clone();
|
||||||
preload_flags.inspect = None;
|
preload_flags.inspect = None;
|
||||||
preload_flags.inspect_brk = None;
|
preload_flags.inspect_brk = None;
|
||||||
let permissions = Permissions::from_options(&preload_flags.clone().into());
|
let permissions = Permissions::from_options(&preload_flags.clone().into());
|
||||||
let program_state = ProgramState::build(preload_flags).await?;
|
let program_state = ProgramState::build(preload_flags).await?;
|
||||||
let main_module = resolve_url_or_path(&module_url)?;
|
let main_module = resolve_url_or_path(&install_flags.module_url)?;
|
||||||
let mut worker =
|
let mut worker =
|
||||||
create_main_worker(&program_state, main_module.clone(), permissions, None);
|
create_main_worker(&program_state, main_module.clone(), permissions, None);
|
||||||
// First, fetch and compile the module; this step ensures that the module exists.
|
// First, fetch and compile the module; this step ensures that the module exists.
|
||||||
worker.preload_module(&main_module).await?;
|
worker.preload_module(&main_module).await?;
|
||||||
tools::installer::install(flags, &module_url, args, name, root, force)
|
tools::installer::install(
|
||||||
|
flags,
|
||||||
|
&install_flags.module_url,
|
||||||
|
install_flags.args,
|
||||||
|
install_flags.name,
|
||||||
|
install_flags.root,
|
||||||
|
install_flags.force,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn lsp_command() -> Result<(), AnyError> {
|
async fn lsp_command() -> Result<(), AnyError> {
|
||||||
|
@ -492,16 +512,10 @@ async fn lsp_command() -> Result<(), AnyError> {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn lint_command(
|
async fn lint_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
files: Vec<PathBuf>,
|
lint_flags: LintFlags,
|
||||||
list_rules: bool,
|
|
||||||
rules_tags: Vec<String>,
|
|
||||||
rules_include: Vec<String>,
|
|
||||||
rules_exclude: Vec<String>,
|
|
||||||
ignore: Vec<PathBuf>,
|
|
||||||
json: bool,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
if list_rules {
|
if lint_flags.rules {
|
||||||
tools::lint::print_rules_list(json);
|
tools::lint::print_rules_list(lint_flags.json);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,19 +529,19 @@ async fn lint_command(
|
||||||
|
|
||||||
tools::lint::lint_files(
|
tools::lint::lint_files(
|
||||||
maybe_lint_config,
|
maybe_lint_config,
|
||||||
rules_tags,
|
lint_flags.rules_tags,
|
||||||
rules_include,
|
lint_flags.rules_include,
|
||||||
rules_exclude,
|
lint_flags.rules_exclude,
|
||||||
files,
|
lint_flags.files,
|
||||||
ignore,
|
lint_flags.ignore,
|
||||||
json,
|
lint_flags.json,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cache_command(
|
async fn cache_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
files: Vec<String>,
|
cache_flags: CacheFlags,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let lib = if flags.unstable {
|
let lib = if flags.unstable {
|
||||||
module_graph::TypeLib::UnstableDenoWindow
|
module_graph::TypeLib::UnstableDenoWindow
|
||||||
|
@ -536,7 +550,7 @@ async fn cache_command(
|
||||||
};
|
};
|
||||||
let program_state = ProgramState::build(flags).await?;
|
let program_state = ProgramState::build(flags).await?;
|
||||||
|
|
||||||
for file in files {
|
for file in cache_flags.files {
|
||||||
let specifier = resolve_url_or_path(&file)?;
|
let specifier = resolve_url_or_path(&file)?;
|
||||||
program_state
|
program_state
|
||||||
.prepare_module_load(
|
.prepare_module_load(
|
||||||
|
@ -555,9 +569,7 @@ async fn cache_command(
|
||||||
|
|
||||||
async fn eval_command(
|
async fn eval_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
code: String,
|
eval_flags: EvalFlags,
|
||||||
ext: String,
|
|
||||||
print: bool,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
// Force TypeScript compile.
|
// Force TypeScript compile.
|
||||||
let main_module = resolve_url_or_path("./$deno$eval.ts").unwrap();
|
let main_module = resolve_url_or_path("./$deno$eval.ts").unwrap();
|
||||||
|
@ -566,21 +578,21 @@ async fn eval_command(
|
||||||
let mut worker =
|
let mut worker =
|
||||||
create_main_worker(&program_state, main_module.clone(), permissions, None);
|
create_main_worker(&program_state, main_module.clone(), permissions, None);
|
||||||
// Create a dummy source file.
|
// Create a dummy source file.
|
||||||
let source_code = if print {
|
let source_code = if eval_flags.print {
|
||||||
format!("console.log({})", code)
|
format!("console.log({})", eval_flags.code)
|
||||||
} else {
|
} else {
|
||||||
code
|
eval_flags.code
|
||||||
}
|
}
|
||||||
.into_bytes();
|
.into_bytes();
|
||||||
|
|
||||||
let file = File {
|
let file = File {
|
||||||
local: main_module.clone().to_file_path().unwrap(),
|
local: main_module.clone().to_file_path().unwrap(),
|
||||||
maybe_types: None,
|
maybe_types: None,
|
||||||
media_type: if ext.as_str() == "ts" {
|
media_type: if eval_flags.ext.as_str() == "ts" {
|
||||||
MediaType::TypeScript
|
MediaType::TypeScript
|
||||||
} else if ext.as_str() == "tsx" {
|
} else if eval_flags.ext.as_str() == "tsx" {
|
||||||
MediaType::Tsx
|
MediaType::Tsx
|
||||||
} else if ext.as_str() == "js" {
|
} else if eval_flags.ext.as_str() == "js" {
|
||||||
MediaType::JavaScript
|
MediaType::JavaScript
|
||||||
} else {
|
} else {
|
||||||
MediaType::Jsx
|
MediaType::Jsx
|
||||||
|
@ -682,15 +694,14 @@ fn bundle_module_graph(
|
||||||
|
|
||||||
async fn bundle_command(
|
async fn bundle_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
source_file: String,
|
bundle_flags: BundleFlags,
|
||||||
out_file: Option<PathBuf>,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let debug = flags.log_level == Some(log::Level::Debug);
|
let debug = flags.log_level == Some(log::Level::Debug);
|
||||||
|
|
||||||
let resolver = |_| {
|
let resolver = |_| {
|
||||||
let flags = flags.clone();
|
let flags = flags.clone();
|
||||||
let source_file1 = source_file.clone();
|
let source_file1 = bundle_flags.source_file.clone();
|
||||||
let source_file2 = source_file.clone();
|
let source_file2 = bundle_flags.source_file.clone();
|
||||||
async move {
|
async move {
|
||||||
let module_specifier = resolve_url_or_path(&source_file1)?;
|
let module_specifier = resolve_url_or_path(&source_file1)?;
|
||||||
|
|
||||||
|
@ -736,7 +747,7 @@ async fn bundle_command(
|
||||||
module_graph::Graph,
|
module_graph::Graph,
|
||||||
)| {
|
)| {
|
||||||
let flags = flags.clone();
|
let flags = flags.clone();
|
||||||
let out_file = out_file.clone();
|
let out_file = bundle_flags.out_file.clone();
|
||||||
async move {
|
async move {
|
||||||
info!("{} {}", colors::green("Bundle"), module_graph.info()?.root);
|
info!("{} {}", colors::green("Bundle"), module_graph.info()?.root);
|
||||||
|
|
||||||
|
@ -780,33 +791,37 @@ async fn bundle_command(
|
||||||
|
|
||||||
async fn doc_command(
|
async fn doc_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
source_file: Option<String>,
|
doc_flags: DocFlags,
|
||||||
json: bool,
|
|
||||||
maybe_filter: Option<String>,
|
|
||||||
private: bool,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
tools::doc::print_docs(flags, source_file, json, maybe_filter, private).await
|
tools::doc::print_docs(
|
||||||
|
flags,
|
||||||
|
doc_flags.source_file,
|
||||||
|
doc_flags.json,
|
||||||
|
doc_flags.filter,
|
||||||
|
doc_flags.private,
|
||||||
|
)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn format_command(
|
async fn format_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
args: Vec<PathBuf>,
|
fmt_flags: FmtFlags,
|
||||||
ignore: Vec<PathBuf>,
|
|
||||||
check: bool,
|
|
||||||
ext: String,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
if args.len() == 1 && args[0].to_string_lossy() == "-" {
|
if fmt_flags.files.len() == 1 && fmt_flags.files[0].to_string_lossy() == "-" {
|
||||||
return tools::fmt::format_stdin(check, ext);
|
return tools::fmt::format_stdin(fmt_flags.check, fmt_flags.ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
tools::fmt::format(args, ignore, check, flags.watch).await?;
|
tools::fmt::format(
|
||||||
|
fmt_flags.files,
|
||||||
|
fmt_flags.ignore,
|
||||||
|
fmt_flags.check,
|
||||||
|
flags.watch,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_repl(
|
async fn run_repl(flags: Flags, repl_flags: ReplFlags) -> Result<(), AnyError> {
|
||||||
flags: Flags,
|
|
||||||
maybe_eval: Option<String>,
|
|
||||||
) -> Result<(), AnyError> {
|
|
||||||
let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap();
|
let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap();
|
||||||
let permissions = Permissions::from_options(&flags.clone().into());
|
let permissions = Permissions::from_options(&flags.clone().into());
|
||||||
let program_state = ProgramState::build(flags).await?;
|
let program_state = ProgramState::build(flags).await?;
|
||||||
|
@ -814,7 +829,7 @@ async fn run_repl(
|
||||||
create_main_worker(&program_state, main_module.clone(), permissions, None);
|
create_main_worker(&program_state, main_module.clone(), permissions, None);
|
||||||
worker.run_event_loop(false).await?;
|
worker.run_event_loop(false).await?;
|
||||||
|
|
||||||
tools::repl::run(&program_state, worker, maybe_eval).await
|
tools::repl::run(&program_state, worker, repl_flags.eval).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> {
|
async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> {
|
||||||
|
@ -991,17 +1006,20 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> {
|
||||||
file_watcher::watch_func(resolver, operation, "Process").await
|
file_watcher::watch_func(resolver, operation, "Process").await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_command(flags: Flags, script: String) -> Result<(), AnyError> {
|
async fn run_command(
|
||||||
|
flags: Flags,
|
||||||
|
run_flags: RunFlags,
|
||||||
|
) -> Result<(), AnyError> {
|
||||||
// Read script content from stdin
|
// Read script content from stdin
|
||||||
if script == "-" {
|
if run_flags.script == "-" {
|
||||||
return run_from_stdin(flags).await;
|
return run_from_stdin(flags).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.watch {
|
if flags.watch {
|
||||||
return run_with_watch(flags, script).await;
|
return run_with_watch(flags, run_flags.script).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let main_module = resolve_url_or_path(&script)?;
|
let main_module = resolve_url_or_path(&run_flags.script)?;
|
||||||
let program_state = ProgramState::build(flags.clone()).await?;
|
let program_state = ProgramState::build(flags.clone()).await?;
|
||||||
let permissions = Permissions::from_options(&flags.clone().into());
|
let permissions = Permissions::from_options(&flags.clone().into());
|
||||||
let mut worker =
|
let mut worker =
|
||||||
|
@ -1046,39 +1064,26 @@ async fn run_command(flags: Flags, script: String) -> Result<(), AnyError> {
|
||||||
|
|
||||||
async fn coverage_command(
|
async fn coverage_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
files: Vec<PathBuf>,
|
coverage_flags: CoverageFlags,
|
||||||
ignore: Vec<PathBuf>,
|
|
||||||
include: Vec<String>,
|
|
||||||
exclude: Vec<String>,
|
|
||||||
lcov: bool,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
if files.is_empty() {
|
if coverage_flags.files.is_empty() {
|
||||||
return Err(generic_error("No matching coverage profiles found"));
|
return Err(generic_error("No matching coverage profiles found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
tools::coverage::cover_files(
|
tools::coverage::cover_files(
|
||||||
flags.clone(),
|
flags.clone(),
|
||||||
files,
|
coverage_flags.files,
|
||||||
ignore,
|
coverage_flags.ignore,
|
||||||
include,
|
coverage_flags.include,
|
||||||
exclude,
|
coverage_flags.exclude,
|
||||||
lcov,
|
coverage_flags.lcov,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
async fn test_command(
|
async fn test_command(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
include: Option<Vec<String>>,
|
test_flags: TestFlags,
|
||||||
ignore: Vec<PathBuf>,
|
|
||||||
no_run: bool,
|
|
||||||
doc: bool,
|
|
||||||
fail_fast: Option<NonZeroUsize>,
|
|
||||||
allow_none: bool,
|
|
||||||
filter: Option<String>,
|
|
||||||
shuffle: Option<u64>,
|
|
||||||
concurrent_jobs: NonZeroUsize,
|
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
if let Some(ref coverage_dir) = flags.coverage_dir {
|
if let Some(ref coverage_dir) = flags.coverage_dir {
|
||||||
std::fs::create_dir_all(&coverage_dir)?;
|
std::fs::create_dir_all(&coverage_dir)?;
|
||||||
|
@ -1091,14 +1096,14 @@ async fn test_command(
|
||||||
if flags.watch {
|
if flags.watch {
|
||||||
tools::test::run_tests_with_watch(
|
tools::test::run_tests_with_watch(
|
||||||
flags,
|
flags,
|
||||||
include,
|
test_flags.include,
|
||||||
ignore,
|
test_flags.ignore,
|
||||||
doc,
|
test_flags.doc,
|
||||||
no_run,
|
test_flags.no_run,
|
||||||
fail_fast,
|
test_flags.fail_fast,
|
||||||
filter,
|
test_flags.filter,
|
||||||
shuffle,
|
test_flags.shuffle,
|
||||||
concurrent_jobs,
|
test_flags.concurrent_jobs,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -1107,15 +1112,15 @@ async fn test_command(
|
||||||
|
|
||||||
tools::test::run_tests(
|
tools::test::run_tests(
|
||||||
flags,
|
flags,
|
||||||
include,
|
test_flags.include,
|
||||||
ignore,
|
test_flags.ignore,
|
||||||
doc,
|
test_flags.doc,
|
||||||
no_run,
|
test_flags.no_run,
|
||||||
fail_fast,
|
test_flags.fail_fast,
|
||||||
allow_none,
|
test_flags.allow_none,
|
||||||
filter,
|
test_flags.filter,
|
||||||
shuffle,
|
test_flags.shuffle,
|
||||||
concurrent_jobs,
|
test_flags.concurrent_jobs,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -1150,102 +1155,47 @@ fn get_subcommand(
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<(), AnyError>>>> {
|
) -> Pin<Box<dyn Future<Output = Result<(), AnyError>>>> {
|
||||||
match flags.clone().subcommand {
|
match flags.clone().subcommand {
|
||||||
DenoSubcommand::Bundle {
|
DenoSubcommand::Bundle(bundle_flags) => {
|
||||||
source_file,
|
bundle_command(flags, bundle_flags).boxed_local()
|
||||||
out_file,
|
|
||||||
} => bundle_command(flags, source_file, out_file).boxed_local(),
|
|
||||||
DenoSubcommand::Doc {
|
|
||||||
source_file,
|
|
||||||
json,
|
|
||||||
filter,
|
|
||||||
private,
|
|
||||||
} => doc_command(flags, source_file, json, filter, private).boxed_local(),
|
|
||||||
DenoSubcommand::Eval { print, code, ext } => {
|
|
||||||
eval_command(flags, code, ext, print).boxed_local()
|
|
||||||
}
|
}
|
||||||
DenoSubcommand::Cache { files } => {
|
DenoSubcommand::Doc(doc_flags) => {
|
||||||
cache_command(flags, files).boxed_local()
|
doc_command(flags, doc_flags).boxed_local()
|
||||||
}
|
}
|
||||||
DenoSubcommand::Compile {
|
DenoSubcommand::Eval(eval_flags) => {
|
||||||
source_file,
|
eval_command(flags, eval_flags).boxed_local()
|
||||||
output,
|
|
||||||
args,
|
|
||||||
target,
|
|
||||||
} => {
|
|
||||||
compile_command(flags, source_file, output, args, target).boxed_local()
|
|
||||||
}
|
}
|
||||||
DenoSubcommand::Coverage {
|
DenoSubcommand::Cache(cache_flags) => {
|
||||||
files,
|
cache_command(flags, cache_flags).boxed_local()
|
||||||
ignore,
|
|
||||||
include,
|
|
||||||
exclude,
|
|
||||||
lcov,
|
|
||||||
} => coverage_command(flags, files, ignore, include, exclude, lcov)
|
|
||||||
.boxed_local(),
|
|
||||||
DenoSubcommand::Fmt {
|
|
||||||
check,
|
|
||||||
files,
|
|
||||||
ignore,
|
|
||||||
ext,
|
|
||||||
} => format_command(flags, files, ignore, check, ext).boxed_local(),
|
|
||||||
DenoSubcommand::Info { file, json } => {
|
|
||||||
info_command(flags, file, json).boxed_local()
|
|
||||||
}
|
}
|
||||||
DenoSubcommand::Install {
|
DenoSubcommand::Compile(compile_flags) => {
|
||||||
module_url,
|
compile_command(flags, compile_flags).boxed_local()
|
||||||
args,
|
}
|
||||||
name,
|
DenoSubcommand::Coverage(coverage_flags) => {
|
||||||
root,
|
coverage_command(flags, coverage_flags).boxed_local()
|
||||||
force,
|
}
|
||||||
} => {
|
DenoSubcommand::Fmt(fmt_flags) => {
|
||||||
install_command(flags, module_url, args, name, root, force).boxed_local()
|
format_command(flags, fmt_flags).boxed_local()
|
||||||
|
}
|
||||||
|
DenoSubcommand::Info(info_flags) => {
|
||||||
|
info_command(flags, info_flags).boxed_local()
|
||||||
|
}
|
||||||
|
DenoSubcommand::Install(install_flags) => {
|
||||||
|
install_command(flags, install_flags).boxed_local()
|
||||||
}
|
}
|
||||||
DenoSubcommand::Lsp => lsp_command().boxed_local(),
|
DenoSubcommand::Lsp => lsp_command().boxed_local(),
|
||||||
DenoSubcommand::Lint {
|
DenoSubcommand::Lint(lint_flags) => {
|
||||||
files,
|
lint_command(flags, lint_flags).boxed_local()
|
||||||
rules,
|
}
|
||||||
rules_tags,
|
DenoSubcommand::Repl(repl_flags) => {
|
||||||
rules_include,
|
run_repl(flags, repl_flags).boxed_local()
|
||||||
rules_exclude,
|
}
|
||||||
ignore,
|
DenoSubcommand::Run(run_flags) => {
|
||||||
json,
|
run_command(flags, run_flags).boxed_local()
|
||||||
} => lint_command(
|
}
|
||||||
flags,
|
DenoSubcommand::Test(test_flags) => {
|
||||||
files,
|
test_command(flags, test_flags).boxed_local()
|
||||||
rules,
|
}
|
||||||
rules_tags,
|
DenoSubcommand::Completions(CompletionsFlags { buf }) => {
|
||||||
rules_include,
|
|
||||||
rules_exclude,
|
|
||||||
ignore,
|
|
||||||
json,
|
|
||||||
)
|
|
||||||
.boxed_local(),
|
|
||||||
DenoSubcommand::Repl { eval } => run_repl(flags, eval).boxed_local(),
|
|
||||||
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
|
|
||||||
DenoSubcommand::Test {
|
|
||||||
no_run,
|
|
||||||
doc,
|
|
||||||
fail_fast,
|
|
||||||
ignore,
|
|
||||||
include,
|
|
||||||
allow_none,
|
|
||||||
filter,
|
|
||||||
shuffle,
|
|
||||||
concurrent_jobs,
|
|
||||||
} => test_command(
|
|
||||||
flags,
|
|
||||||
include,
|
|
||||||
ignore,
|
|
||||||
no_run,
|
|
||||||
doc,
|
|
||||||
fail_fast,
|
|
||||||
allow_none,
|
|
||||||
filter,
|
|
||||||
shuffle,
|
|
||||||
concurrent_jobs,
|
|
||||||
)
|
|
||||||
.boxed_local(),
|
|
||||||
DenoSubcommand::Completions { buf } => {
|
|
||||||
if let Err(e) = write_to_stdout_ignore_sigpipe(&buf) {
|
if let Err(e) = write_to_stdout_ignore_sigpipe(&buf) {
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
@ -1260,17 +1210,20 @@ fn get_subcommand(
|
||||||
}
|
}
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
DenoSubcommand::Upgrade {
|
DenoSubcommand::Upgrade(upgrade_flags) => {
|
||||||
force,
|
let UpgradeFlags {
|
||||||
dry_run,
|
force,
|
||||||
canary,
|
dry_run,
|
||||||
version,
|
canary,
|
||||||
output,
|
version,
|
||||||
ca_file,
|
output,
|
||||||
} => tools::upgrade::upgrade_command(
|
ca_file,
|
||||||
dry_run, force, canary, version, output, ca_file,
|
} = upgrade_flags;
|
||||||
)
|
tools::upgrade::upgrade_command(
|
||||||
.boxed_local(),
|
dry_run, force, canary, version, output, ca_file,
|
||||||
|
)
|
||||||
|
.boxed_local()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use crate::deno_dir::DenoDir;
|
use crate::deno_dir::DenoDir;
|
||||||
use crate::flags::DenoSubcommand;
|
use crate::flags::DenoSubcommand;
|
||||||
use crate::flags::Flags;
|
use crate::flags::Flags;
|
||||||
|
use crate::flags::RunFlags;
|
||||||
use deno_core::error::bail;
|
use deno_core::error::bail;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::serde_json;
|
use deno_core::serde_json;
|
||||||
|
@ -199,9 +200,9 @@ pub fn compile_to_runtime_flags(
|
||||||
// change to `Flags` should be reflected here.
|
// change to `Flags` should be reflected here.
|
||||||
Ok(Flags {
|
Ok(Flags {
|
||||||
argv: baked_args,
|
argv: baked_args,
|
||||||
subcommand: DenoSubcommand::Run {
|
subcommand: DenoSubcommand::Run(RunFlags {
|
||||||
script: "placeholder".to_string(),
|
script: "placeholder".to_string(),
|
||||||
},
|
}),
|
||||||
allow_env: flags.allow_env,
|
allow_env: flags.allow_env,
|
||||||
allow_hrtime: flags.allow_hrtime,
|
allow_hrtime: flags.allow_hrtime,
|
||||||
allow_net: flags.allow_net,
|
allow_net: flags.allow_net,
|
||||||
|
|
Loading…
Reference in a new issue