Skip to content

Commit

Permalink
use: show warning if setting a version that will not be used
Browse files Browse the repository at this point in the history
e.g.: `rtx use -g node@18` if there is a local .rtx.toml with node already defined
  • Loading branch information
jdx committed Dec 14, 2023
1 parent f3c32cb commit 3e58555
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions e2e/ruby/test_ruby
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export RTX_RUBY_DEFAULT_PACKAGES_FILE="$ROOT/e2e/.default-gems"
export RTX_RUBY_VERBOSE_INSTALL=1
export RTX_RAW=1

if [ "${TEST_ALL:-}" != 1 ]; then
exit
fi
# if [ "${TEST_ALL:-}" != 1 ]; then
# exit
# fi

cat >Gemfile <<EOF
# frozen_string_literal: true
Expand Down
25 changes: 23 additions & 2 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use crate::config::config_file::ConfigFile;
use crate::config::{config_file, Config};
use crate::env::{RTX_DEFAULT_CONFIG_FILENAME, RTX_DEFAULT_TOOL_VERSIONS_FILENAME};
use crate::file::display_path;

use crate::plugins::PluginName;
use crate::toolset::{InstallOptions, ToolsetBuilder};
use crate::toolset::{InstallOptions, ToolSource, ToolsetBuilder};
use crate::{dirs, env, file};

/// Change the active version of a tool locally or globally.
Expand Down Expand Up @@ -112,6 +111,9 @@ impl Use {
cf.replace_versions(&plugin_name, &versions);
}

if self.global {
self.warn_if_hidden(&config, cf.get_path());
}
for plugin_name in self.remove.unwrap_or_default() {
cf.remove_plugin(&plugin_name);
}
Expand All @@ -138,6 +140,25 @@ impl Use {
};
config_file::parse_or_init(&config.settings, &path)
}

fn warn_if_hidden(&self, config: &Config, global: &Path) {
let ts = ToolsetBuilder::new().build(config).unwrap_or_default();
let warn = |targ: &ToolArg, p| {
let plugin = &targ.plugin;
let p = display_path(p);
let global = display_path(global);
warn!("{plugin} is is defined in {p} which overrides the global config ({global})");
};
for targ in &self.tool {
if let Some(tv) = ts.versions.get(&targ.plugin) {
if let ToolSource::RtxToml(p) | ToolSource::ToolVersions(p) = &tv.source {
if p != global {
warn(targ, p);
}
}
}
}
}
}

fn global_file() -> PathBuf {
Expand Down

0 comments on commit 3e58555

Please sign in to comment.