summaryrefslogtreecommitdiff
path: root/cli/args/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r--cli/args/mod.rs28
1 files changed, 23 insertions, 5 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 17bbf0603..5844b0fa7 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -44,6 +44,14 @@ use crate::file_fetcher::CacheSetting;
use crate::lockfile::Lockfile;
use crate::version;
+/// Overrides for the options below that when set will
+/// use these values over the values derived from the
+/// CLI flags or config file.
+#[derive(Default)]
+struct CliOptionOverrides {
+ import_map_specifier: Option<Option<ModuleSpecifier>>,
+}
+
/// Holds the common options used by many sub commands
/// and provides some helper function for creating common objects.
pub struct CliOptions {
@@ -51,6 +59,7 @@ pub struct CliOptions {
// application need not concern itself with, so keep these private
flags: Flags,
maybe_config_file: Option<ConfigFile>,
+ overrides: CliOptionOverrides,
}
impl CliOptions {
@@ -72,6 +81,7 @@ impl CliOptions {
Ok(Self {
maybe_config_file,
flags,
+ overrides: Default::default(),
})
}
@@ -113,13 +123,21 @@ impl CliOptions {
/// Based on an optional command line import map path and an optional
/// configuration file, return a resolved module specifier to an import map.
- pub fn resolve_import_map_path(
+ pub fn resolve_import_map_specifier(
&self,
) -> Result<Option<ModuleSpecifier>, AnyError> {
- resolve_import_map_specifier(
- self.flags.import_map_path.as_deref(),
- self.maybe_config_file.as_ref(),
- )
+ match self.overrides.import_map_specifier.clone() {
+ Some(path) => Ok(path),
+ None => resolve_import_map_specifier(
+ self.flags.import_map_path.as_deref(),
+ self.maybe_config_file.as_ref(),
+ ),
+ }
+ }
+
+ /// Overrides the import map specifier to use.
+ pub fn set_import_map_specifier(&mut self, path: Option<ModuleSpecifier>) {
+ self.overrides.import_map_specifier = Some(path);
}
pub fn resolve_root_cert_store(&self) -> Result<RootCertStore, AnyError> {