use crate::{ExpectedError, Result};
use camino::{Utf8Path, Utf8PathBuf};
use clap::Args;
use nextest_filtering::ParseContext;
use nextest_runner::config::core::{NextestConfig, ToolConfigFile, VersionOnlyConfig};
use std::collections::BTreeSet;
#[derive(Debug, Args)]
pub(crate) struct CommonOpts {
#[arg(
long,
global = true,
value_name = "PATH",
help_heading = "Manifest options"
)]
pub(crate) manifest_path: Option<Utf8PathBuf>,
#[clap(flatten)]
pub(crate) output: crate::output::OutputOpts,
#[clap(flatten)]
pub(crate) config_opts: ConfigOpts,
}
#[derive(Debug, Args)]
#[command(next_help_heading = "Config options")]
pub(crate) struct ConfigOpts {
#[arg(long, global = true, value_name = "PATH")]
pub config_file: Option<Utf8PathBuf>,
#[arg(long = "tool-config-file", global = true, value_name = "TOOL:ABS_PATH")]
pub tool_config_files: Vec<ToolConfigFile>,
#[arg(long, global = true)]
pub override_version_check: bool,
#[arg(
long,
short = 'P',
env = "NEXTEST_PROFILE",
global = true,
help_heading = "Config options"
)]
pub(crate) profile: Option<String>,
}
impl ConfigOpts {
pub(crate) fn make_version_only_config(
&self,
workspace_root: &Utf8Path,
) -> Result<VersionOnlyConfig> {
VersionOnlyConfig::from_sources(
workspace_root,
self.config_file.as_deref(),
&self.tool_config_files,
)
.map_err(ExpectedError::config_parse_error)
}
pub(crate) fn make_config(
&self,
workspace_root: &Utf8Path,
pcx: &ParseContext<'_>,
experimental: &BTreeSet<nextest_runner::config::core::ConfigExperimental>,
) -> Result<NextestConfig> {
NextestConfig::from_sources(
workspace_root,
pcx,
self.config_file.as_deref(),
&self.tool_config_files,
experimental,
)
.map_err(ExpectedError::config_parse_error)
}
}