mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
move -c handling to CliOptions methods
This commit is contained in:
parent
0e2f9e7c10
commit
f45d39b20b
5 changed files with 103 additions and 112 deletions
114
cli/args/mod.rs
114
cli/args/mod.rs
|
@ -1027,10 +1027,6 @@ impl CliOptions {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_discovered_config(&self) -> bool {
|
||||
self.flags.is_discovered_config()
|
||||
}
|
||||
|
||||
pub fn npm_system_info(&self) -> NpmSystemInfo {
|
||||
match self.sub_command() {
|
||||
DenoSubcommand::Compile(CompileFlags {
|
||||
|
@ -1342,12 +1338,22 @@ impl CliOptions {
|
|||
pub fn resolve_fmt_options_for_members(
|
||||
&self,
|
||||
fmt_flags: &FmtFlags,
|
||||
) -> Result<Vec<(WorkspaceDirectory, FmtOptions)>, AnyError> {
|
||||
) -> Result<Vec<(Arc<WorkspaceDirectory>, FmtOptions)>, AnyError> {
|
||||
let cli_arg_patterns =
|
||||
fmt_flags.files.as_file_patterns(self.initial_cwd())?;
|
||||
let member_configs = self
|
||||
.workspace()
|
||||
.resolve_fmt_config_for_members(&cli_arg_patterns)?;
|
||||
let member_configs = if self.flags.is_discovered_config() {
|
||||
self
|
||||
.workspace()
|
||||
.resolve_fmt_config_for_members(&cli_arg_patterns)?
|
||||
.into_iter()
|
||||
.map(|(d, c)| (Arc::new(d), c))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
vec![(
|
||||
self.start_dir.clone(),
|
||||
self.start_dir.to_fmt_config(cli_arg_patterns)?,
|
||||
)]
|
||||
};
|
||||
let unstable = self.resolve_config_unstable_fmt_options();
|
||||
let mut result = Vec::with_capacity(member_configs.len());
|
||||
for (ctx, config) in member_configs {
|
||||
|
@ -1376,23 +1382,43 @@ impl CliOptions {
|
|||
pub fn resolve_file_flags_for_members(
|
||||
&self,
|
||||
file_flags: &FileFlags,
|
||||
) -> Result<Vec<(WorkspaceDirectory, FilePatterns)>, AnyError> {
|
||||
) -> Result<Vec<(Arc<WorkspaceDirectory>, FilePatterns)>, AnyError> {
|
||||
let cli_arg_patterns = file_flags.as_file_patterns(self.initial_cwd())?;
|
||||
let member_patterns = self
|
||||
.workspace()
|
||||
.resolve_file_patterns_for_members(&cli_arg_patterns)?;
|
||||
let member_patterns = if self.flags.is_discovered_config() {
|
||||
self
|
||||
.workspace()
|
||||
.resolve_file_patterns_for_members(&cli_arg_patterns)?
|
||||
.into_iter()
|
||||
.map(|(d, p)| (Arc::new(d), p))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
vec![(
|
||||
self.start_dir.clone(),
|
||||
self.start_dir.to_resolved_file_patterns(cli_arg_patterns)?,
|
||||
)]
|
||||
};
|
||||
Ok(member_patterns)
|
||||
}
|
||||
|
||||
pub fn resolve_lint_options_for_members(
|
||||
&self,
|
||||
lint_flags: &LintFlags,
|
||||
) -> Result<Vec<(WorkspaceDirectory, LintOptions)>, AnyError> {
|
||||
) -> Result<Vec<(Arc<WorkspaceDirectory>, LintOptions)>, AnyError> {
|
||||
let cli_arg_patterns =
|
||||
lint_flags.files.as_file_patterns(self.initial_cwd())?;
|
||||
let member_configs = self
|
||||
.workspace()
|
||||
.resolve_lint_config_for_members(&cli_arg_patterns)?;
|
||||
let member_configs = if self.flags.is_discovered_config() {
|
||||
self
|
||||
.workspace()
|
||||
.resolve_lint_config_for_members(&cli_arg_patterns)?
|
||||
.into_iter()
|
||||
.map(|(d, c)| (Arc::new(d), c))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
vec![(
|
||||
self.start_dir.clone(),
|
||||
self.start_dir.to_lint_config(cli_arg_patterns)?,
|
||||
)]
|
||||
};
|
||||
let mut result = Vec::with_capacity(member_configs.len());
|
||||
for (ctx, config) in member_configs {
|
||||
let options = LintOptions::resolve(config, lint_flags);
|
||||
|
@ -1430,18 +1456,26 @@ impl CliOptions {
|
|||
pub fn resolve_test_options_for_members(
|
||||
&self,
|
||||
test_flags: &TestFlags,
|
||||
) -> Result<Vec<(WorkspaceDirectory, TestOptions)>, AnyError> {
|
||||
) -> Result<Vec<(Arc<WorkspaceDirectory>, TestOptions)>, AnyError> {
|
||||
let cli_arg_patterns =
|
||||
test_flags.files.as_file_patterns(self.initial_cwd())?;
|
||||
let workspace_dir_configs = self
|
||||
.workspace()
|
||||
.resolve_test_config_for_members(&cli_arg_patterns)?;
|
||||
let mut result = Vec::with_capacity(workspace_dir_configs.len());
|
||||
for (member_dir, config) in workspace_dir_configs {
|
||||
let options = TestOptions::resolve(config, test_flags);
|
||||
result.push((member_dir, options));
|
||||
}
|
||||
Ok(result)
|
||||
let member_options = if self.flags.is_discovered_config() {
|
||||
self
|
||||
.workspace()
|
||||
.resolve_test_config_for_members(&cli_arg_patterns)?
|
||||
.into_iter()
|
||||
.map(|(d, c)| (Arc::new(d), TestOptions::resolve(c, test_flags)))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
vec![(
|
||||
self.start_dir.clone(),
|
||||
TestOptions::resolve(
|
||||
self.start_dir.to_test_config(cli_arg_patterns)?,
|
||||
test_flags,
|
||||
),
|
||||
)]
|
||||
};
|
||||
Ok(member_options)
|
||||
}
|
||||
|
||||
pub fn resolve_workspace_bench_options(
|
||||
|
@ -1454,18 +1488,26 @@ impl CliOptions {
|
|||
pub fn resolve_bench_options_for_members(
|
||||
&self,
|
||||
bench_flags: &BenchFlags,
|
||||
) -> Result<Vec<(WorkspaceDirectory, BenchOptions)>, AnyError> {
|
||||
) -> Result<Vec<(Arc<WorkspaceDirectory>, BenchOptions)>, AnyError> {
|
||||
let cli_arg_patterns =
|
||||
bench_flags.files.as_file_patterns(self.initial_cwd())?;
|
||||
let workspace_dir_configs = self
|
||||
.workspace()
|
||||
.resolve_bench_config_for_members(&cli_arg_patterns)?;
|
||||
let mut result = Vec::with_capacity(workspace_dir_configs.len());
|
||||
for (member_dir, config) in workspace_dir_configs {
|
||||
let options = BenchOptions::resolve(config, bench_flags);
|
||||
result.push((member_dir, options));
|
||||
}
|
||||
Ok(result)
|
||||
let member_options = if self.flags.is_discovered_config() {
|
||||
self
|
||||
.workspace()
|
||||
.resolve_bench_config_for_members(&cli_arg_patterns)?
|
||||
.into_iter()
|
||||
.map(|(d, c)| (Arc::new(d), BenchOptions::resolve(c, bench_flags)))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
vec![(
|
||||
self.start_dir.clone(),
|
||||
BenchOptions::resolve(
|
||||
self.start_dir.to_bench_config(cli_arg_patterns)?,
|
||||
bench_flags,
|
||||
),
|
||||
)]
|
||||
};
|
||||
Ok(member_options)
|
||||
}
|
||||
|
||||
/// Vector of user script CLI arguments.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::args::BenchFlags;
|
||||
use crate::args::BenchOptions;
|
||||
use crate::args::Flags;
|
||||
use crate::colors;
|
||||
use crate::display::write_json_to_stdout;
|
||||
|
@ -433,20 +432,11 @@ pub async fn run_benchmarks(
|
|||
)?;
|
||||
let log_level = cli_options.log_level();
|
||||
|
||||
let workspace_dirs_with_files = if cli_options.is_discovered_config() {
|
||||
cli_options
|
||||
.resolve_bench_options_for_members(&bench_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (Arc::new(d), o.files))
|
||||
.collect()
|
||||
} else {
|
||||
let patterns = bench_flags
|
||||
.files
|
||||
.as_file_patterns(cli_options.initial_cwd())?;
|
||||
let config = cli_options.start_dir.to_bench_config(patterns)?;
|
||||
let options = BenchOptions::resolve(config, &bench_flags);
|
||||
vec![(cli_options.start_dir.clone(), options.files)]
|
||||
};
|
||||
let workspace_dirs_with_files = cli_options
|
||||
.resolve_bench_options_for_members(&bench_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (d, o.files))
|
||||
.collect();
|
||||
let file_container = WorkspaceFileContainer::from_workspace_dirs_with_files(
|
||||
workspace_dirs_with_files,
|
||||
&factory,
|
||||
|
@ -527,20 +517,11 @@ pub async fn run_benchmarks_with_watch(
|
|||
let log_level = cli_options.log_level();
|
||||
|
||||
let _ = watcher_communicator.watch_paths(cli_options.watch_paths());
|
||||
let workspace_dirs_with_files = if cli_options.is_discovered_config() {
|
||||
cli_options
|
||||
.resolve_bench_options_for_members(&bench_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (Arc::new(d), o.files))
|
||||
.collect()
|
||||
} else {
|
||||
let patterns = bench_flags
|
||||
.files
|
||||
.as_file_patterns(cli_options.initial_cwd())?;
|
||||
let config = cli_options.start_dir.to_bench_config(patterns)?;
|
||||
let options = BenchOptions::resolve(config, &bench_flags);
|
||||
vec![(cli_options.start_dir.clone(), options.files)]
|
||||
};
|
||||
let workspace_dirs_with_files = cli_options
|
||||
.resolve_bench_options_for_members(&bench_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (d, o.files))
|
||||
.collect::<Vec<_>>();
|
||||
let watch_paths = workspace_dirs_with_files
|
||||
.iter()
|
||||
.filter_map(|(_, files)| {
|
||||
|
|
|
@ -50,24 +50,11 @@ pub async fn check(
|
|||
) -> Result<(), AnyError> {
|
||||
let factory = CliFactory::from_flags(flags);
|
||||
let cli_options = factory.cli_options()?;
|
||||
let workspace_dirs_with_files = if cli_options.is_discovered_config() {
|
||||
cli_options
|
||||
.resolve_file_flags_for_members(&FileFlags {
|
||||
ignore: Default::default(),
|
||||
include: check_flags.files,
|
||||
})?
|
||||
.into_iter()
|
||||
.map(|(d, p)| (Arc::new(d), p))
|
||||
.collect()
|
||||
} else {
|
||||
let file_flags = FileFlags {
|
||||
let workspace_dirs_with_files =
|
||||
cli_options.resolve_file_flags_for_members(&FileFlags {
|
||||
ignore: Default::default(),
|
||||
include: check_flags.files,
|
||||
};
|
||||
let patterns = file_flags.as_file_patterns(cli_options.initial_cwd())?;
|
||||
let patterns = cli_options.start_dir.to_resolved_file_patterns(patterns)?;
|
||||
vec![(cli_options.start_dir.clone(), patterns)]
|
||||
};
|
||||
})?;
|
||||
let file_container = WorkspaceFileContainer::from_workspace_dirs_with_files(
|
||||
workspace_dirs_with_files,
|
||||
&factory,
|
||||
|
|
|
@ -200,7 +200,7 @@ pub async fn lint(
|
|||
}
|
||||
|
||||
struct PathsWithOptions {
|
||||
dir: WorkspaceDirectory,
|
||||
dir: Arc<WorkspaceDirectory>,
|
||||
paths: Vec<PathBuf>,
|
||||
options: LintOptions,
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ impl WorkspaceLinter {
|
|||
cli_options: &Arc<CliOptions>,
|
||||
lint_options: LintOptions,
|
||||
lint_config: LintConfig,
|
||||
member_dir: WorkspaceDirectory,
|
||||
member_dir: Arc<WorkspaceDirectory>,
|
||||
paths: Vec<PathBuf>,
|
||||
) -> Result<(), AnyError> {
|
||||
self.file_count += paths.len();
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
use crate::args::CliOptions;
|
||||
use crate::args::Flags;
|
||||
use crate::args::TestFlags;
|
||||
use crate::args::TestOptions;
|
||||
use crate::args::TestReporterConfig;
|
||||
use crate::colors;
|
||||
use crate::display;
|
||||
|
@ -1500,20 +1499,11 @@ pub async fn run_tests(
|
|||
)?;
|
||||
let log_level = cli_options.log_level();
|
||||
|
||||
let workspace_dirs_with_files = if cli_options.is_discovered_config() {
|
||||
cli_options
|
||||
.resolve_test_options_for_members(&test_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (Arc::new(d), o.files))
|
||||
.collect()
|
||||
} else {
|
||||
let patterns = test_flags
|
||||
.files
|
||||
.as_file_patterns(cli_options.initial_cwd())?;
|
||||
let config = cli_options.start_dir.to_test_config(patterns)?;
|
||||
let options = TestOptions::resolve(config, &test_flags);
|
||||
vec![(cli_options.start_dir.clone(), options.files)]
|
||||
};
|
||||
let workspace_dirs_with_files = cli_options
|
||||
.resolve_test_options_for_members(&test_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (d, o.files))
|
||||
.collect();
|
||||
let file_container = WorkspaceFileContainer::from_workspace_dirs_with_files(
|
||||
workspace_dirs_with_files,
|
||||
&factory,
|
||||
|
@ -1616,20 +1606,11 @@ pub async fn run_tests_with_watch(
|
|||
let log_level = cli_options.log_level();
|
||||
|
||||
let _ = watcher_communicator.watch_paths(cli_options.watch_paths());
|
||||
let workspace_dirs_with_files = if cli_options.is_discovered_config() {
|
||||
cli_options
|
||||
.resolve_test_options_for_members(&test_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (Arc::new(d), o.files))
|
||||
.collect()
|
||||
} else {
|
||||
let patterns = test_flags
|
||||
.files
|
||||
.as_file_patterns(cli_options.initial_cwd())?;
|
||||
let config = cli_options.start_dir.to_test_config(patterns)?;
|
||||
let options = TestOptions::resolve(config, &test_flags);
|
||||
vec![(cli_options.start_dir.clone(), options.files)]
|
||||
};
|
||||
let workspace_dirs_with_files = cli_options
|
||||
.resolve_test_options_for_members(&test_flags)?
|
||||
.into_iter()
|
||||
.map(|(d, o)| (d, o.files))
|
||||
.collect::<Vec<_>>();
|
||||
let watch_paths = workspace_dirs_with_files
|
||||
.iter()
|
||||
.filter_map(|(_, files)| {
|
||||
|
|
Loading…
Add table
Reference in a new issue